var score = 0;
var alpha=0;
var char=0;
var digit=0;
var testPwd = 0;
var prev="";
var len=0;
var permission_group_id=0;
var mailbox = 0;
var aliases = 0;
var mailBox_authsmtpMail=0;
var aliases_authsmtpMail=0;
dojo.declare("Main", wm.Page, {
    
    start: function() {
		try {
			//alert("hi="+dojo.cookie("user"));
           
             this.userGroupId.update();
             this.myUserID.update();
             this.myUserIdQuery.update();
             this.GroupCombo.update();
             
     } catch(e) {
			app.toastError(this.name + ".start() Failed: " + e.toString()); 
		}
	},

    
 serviceLoadingImgBeforeUpdate: function(inSender, ioInput) {
                  try {
                	   app.pageDialog.showPage("LoadingImg",true,150,50);
            		  
            	  } catch(e) {
            		  console.error('ERROR IN serviceLoadingImgBeforeUpdate: ' + e); 
            	  } 
},
serviceLoadingImgResult: function(inSender, inDeprecated) {
      try {
		  
		  app.pageDialog.dismiss();
	  } catch(e) {
		  console.error('ERROR IN serviceLoadingImgResult: ' + e); 
	  } 
  },
	picture10RightClick: function(inSender, event) {
	  try {
		  
		  
	  } catch(e) {
		  console.error('ERROR IN picture10RightClick: ' + e); 
	  } 
  },
  
 
  testChange: function(inSender, inIndex) {
	  try {
    
	  } catch(e) {
		  console.error('ERROR IN testChange: ' + e); 
	  } 
  },
  
  existDomSuffixChange: function(inSender) {
	  try {
		 
		  
	  } catch(e) {
		  console.error('ERROR IN existDomSuffixChange: ' + e); 
	  } 
  },
  layerHomeShow: function(inSender) {
	  try {
		 
		  
	  } catch(e) {
		  console.error('ERROR IN layerHomeShow: ' + e); 
	  } 
  },
  
  //-----------------------------------------------------------------------------------------------------------------------------------------------
  setGrpCreateGrpNew4Click: function(inSender) {
      try {
            //this.Grpname.setValue("required",true);
            this.GrpPerLiveForm.operation="insert";
            var count=this.GroupCombo.getCount();
            for(var i=0;i<count;i++){
                var record=this.GroupCombo.getData()[i];
                if(this.Grpname.getDataValue()==record.name){
                  return app.alert("Duplicate entry found with '"+record.name+"'");
                  
                }
            }
            if(this.Grpname.getDataValue()==null){this.Grpname.focus(); return app.alert("Group name is required");}
            this.home.setDisplayValue("enabled");
                this.authsmtp.setDisplayValue("enabled");
                this.emaildelivery.setDisplayValue("enabled");
                this.settings.setDisplayValue("enabled");
                this.spamscore.setDisplayValue("enabled");
                this.webmail.setDisplayValue("enabled");
                this.subscriptions.setDisplayValue("enabled");
                this.emaileditor.setDisplayValue("enabled");
                this.bulkmarketing.setDisplayValue("enabled");
            this.GrpPerLiveForm.insertData();
            
                    
      } catch(e) {
		  console.error('ERROR IN setGrpCreateGrpNew4Click: ' + e); 
	  } 
  },
 //Developer Comments:--Event handler to insert Group permission data.
  setGrpExistGrpSave4Click: function(inSender) {
	  try {
           this.GrpPerLiveForm.operation="update";
          this.Grpname.setValue("dataValue",this.Existing_Groups2.getDisplayValue());
           /*var count=this.GroupCombo.getCount();
            for(var i=0;i<count;i++){
                var record=this.GroupCombo.getData()[i];
                if(this.Grpname.getDataValue()==record.name)
                {   
                    if(this.Existing_Groups2.getDataValue()!=record.id){
                        
                        return app.alert("Duplicate entry found with '"+record.name+"'"); 
                        
                    }
                }
            }*/
           if(this.Existing_Groups2.getDataValue()==null){return app.alert("Existing Group is not selected");}
           this.GrpPerLiveForm.updateData();
                      
           } catch(e) {
		  console.error('ERROR IN setGrpExistGrpSave4Click: ' + e); 
	  } 
  },
  //Developer Comments:--Event handler to dete data from Group permission data. .
  setGrpExistGrpDelete4Click: function(inSender) {
      try {
            this.GrpPerLiveForm.operation="delete"; 
            if(this.Existing_Groups2.getDataValue()==null){return app.alert("Existing Group is not selected");}
            this.groupDeleteDialog.show();
           // this.GrpPerLiveForm.deleteData();
            //this.hiddenUserID.setDataValue(this.Userid.getValue("dataValue"));
          } catch(e) {
		  console.error('ERROR IN setGrpExistGrpDelete4Click: ' + e); 
	  } 
  },
  groupDeleteDialogButton1Click: function(inSender, inButton, inText) {
      try {
		     this.GrpPerLiveForm.deleteData();
		  
	  } catch(e) {
		  console.error('ERROR IN groupDeleteDialogButton1Click: ' + e); 
	  } 
  },
  //Developer Comments:--Event handler to check success of Database Transaction.
  GrpPerLiveFormSuccess: function(inSender, inData) {
	  try {
          this.GroupCombo.update();
          var op=this.GrpPerLiveForm.operation;
          if(op=="insert")
          { 
              this.Existing_Groups2.setValue("restrictValues",false);
              var gname=this.Grpname.getDataValue();
              this.Existing_Groups2.setDisplayValue(gname);
             
                
              this.hiddenUserID.setDataValue(this.Userid.getValue("dataValue"));
              this.setGrpPermissionsPanel4.setShowing(true); 
              this.setGrpExistGrpDelete4.setShowing(true);
              this.setGrpExistGrpSave4.setShowing(true);
              //this.Grpname.clear();
          }
          else if(op=="update")
          {
              app.alert("Data Updated successfully");
              this.GrpPerLiveForm.clearData();
              this.hiddenUserID.setDataValue(this.Userid.getValue("dataValue"));
              this.setGrpPermissionsPanel4.setShowing(false); 
              this.setGrpExistGrpDelete4.setShowing(false);
              this.setGrpExistGrpSave4.setShowing(false);
          }
          else if(op=="delete")
          { 
              app.alert("Data Deleted successfully");
              this.hiddenUserID.setDataValue(this.Userid.getValue("dataValue"));
              this.setGrpPermissionsPanel4.setShowing(false);
              this.setGrpExistGrpDelete4.setShowing(false);
              this.setGrpExistGrpSave4.setShowing(false);
          }
           var score = 0;        
          /*this.setGrpExistGrpDelete4.setShowing(false);
          this.setGrpExistGrpSave4.setShowing(false);
          this.setGrpCreateGrpNew4.setShowing(true);*/
          
      } catch(e) {
		  console.error('ERROR IN GrpPerLiveFormSuccess: ' + e); 
	  } 
  },
  GroupComboSuccess: function(inSender, inDeprecated) {
      try {
		  this.Existing_Groups2.setValue("restrictValues",true);
          
	  } catch(e) {
		  console.error('ERROR IN GroupComboSuccess: ' + e); 
	  } 
  },
  //Develper Comments:--
    GrpnameChange: function(inSender) {
         try {
               // alert("onBlur="+this.Grpname.getDataValue());
               /* if(this.Grpname.getDataValue()!= null)
                {this.setGrpPermissionsPanel4.setShowing(true)
                
                ;}
                else
                {this.setGrpPermissionsPanel4.setShowing(false);
                 
                }*/
                
              /*this.home.setDisplayValue("enable");
                this.authsmtp.setDisplayValue("enable");
                this.emaildelivery.setDisplayValue("enable");
                this.settings.setDisplayValue("enable");
                this.spamscore.setDisplayValue("enable");
                this.webmail.setDisplayValue("enable");
                this.subscriptions.setDisplayValue("enable");
                this.emaileditor.setDisplayValue("enable");
                this.bulkmarketing.setDisplayValue("enable");*/
    	  } catch(e) {
    		  console.error('ERROR IN GrpnameBlur: ' + e); 
    	  } 
   },
  
  Existing_Groups2Blur: function(inSender) {
	  try {
           /*if(this.Existing_Groups2.getDataValue()!=null)
           { this.setGrpPermissionsPanel4.setShowing(true); }
           else
           {    if(this.Grpname.getDataValue()!=null)
                {
                    this.setGrpExistGrpDelete4.setShowing(false);
                    this.setGrpExistGrpSave4.setShowing(false);
                    this.setGrpCreateGrpNew4.setShowing(true);
                }
                else{
                this.setGrpPermissionsPanel4.setShowing(false);
                this.setGrpExistGrpDelete4.setShowing(false);
                this.setGrpExistGrpSave4.setShowing(false);
                this.setGrpCreateGrpNew4.setShowing(true);
                this.GrpPerLiveForm.celarData();
                }
           }*/
	  } catch(e) {
		  console.error('ERROR IN Existing_Groups2Blur: ' + e); 
	  } 
  },
  
  //Developer Comments:--Event handler to load data into respectiove field by using livevariable(fillComboGrp.getCount).
  Existing_Groups2Change: function(inSender) {
      try {
           
           var selectedId=this.Existing_Groups2.selectedItem.getValue("id");
           if(selectedId!=null)
           { 
            var count=this.GroupCombo.getCount();
            for(var i=0;i<count;i++){
                var record=this.GroupCombo.getData()[i];
                if(selectedId==record.id){
                    this.Grpname.setDataValue(record.name);
                    this.home.setDataValue(record.home);
                    this.settings.setDataValue(record.settings);
                    this.subscriptions.setDataValue(record.subscriptions);
                    
                    this.authsmtp.setDataValue(record.authsmtp);
                    this.spamscore.setDataValue(record.spamscore);
                   
                    this.emaileditor.setDataValue(record.emaileditor);
                    this.emaildelivery.setDataValue(record.emaildelivery);
                    this.webmail.setDataValue(record.webmail);
                    this.bulkmarketing.setDataValue(record.bulkmarketing);
                    
                    //for the identification if the e_m then show the save and delete image other wise hide image
                    var identifyUser=this.user_Permissions.getData()[0].settings;
                    if(identifyUser=="enabled_modify"){
                        this.setGrpPermissionsPanel4.setShowing(true); 
                        this.setGrpExistGrpDelete4.setShowing(true);
                        this.setGrpExistGrpSave4.setShowing(true);
                    }
                    if(identifyUser=="enabled"){
                        this.setGrpPermissionsPanel4.setShowing(true); 
                        this.setGrpExistGrpDelete4.setShowing(false);
                        this.setGrpExistGrpSave4.setShowing(false);
                    }
                    
                    this.Grpname.clear();
                    
                    break;
                    //this.setGrpCreateGrpNew4.setShowing(false);
                 }
            }
          }
           
	  } catch(e) {
		  console.error('ERROR IN Existing_Groups2Change: ' + e); 
	  } 
  },
 //---------------------------------------------------------------------------------------------------------------------------- 
  setLogCreateLoginNew2Click: function(inSender) {
      try {
              this.loginPerFrm.operation="insert"; 
              var count=this.LoginCombo.getCount();
              for(var i=0;i<count;i++){
                var record=this.LoginCombo.getData()[i];
                if(record.name==this.userName.getDataValue())
                {
                    if(record.username==this.username.getDataValue())
                    {
                        this.username.focus();
                        
                        return app.alert("Username is not available");
                        break;
                    }
                    this.userName.focus();
                    return app.alert("Duplicate Entry Found with '"+record.name+"'");
                    
                }
                
             }
             
            /* count=this.getExtLogin.getCount();
             for(var i=0;i<count;i++){
                var record=this.getExtLogin.getData()[i];
                if(record.username==this.username.getDataValue()){
                      this.username.focus();
                      return app.alert("Username is not available");
                     
                     }
             }*/
              if(this.userName.getDataValue()==null){this.userName.focus(); return app.alert("Login name is required");}
              this.groupid.clear();
              this.username.clear();
              this.password.clear();
              this.ips.clear();
              this.loginPerFrm.insertData();
    } catch(e) {
		  console.error('ERROR IN setLogCreateLoginNew2Click: ' + e); 
	  } 
  },
  //Developer Comments:--Event handler to insert Login permission data.
  setLogExistLoginSave2Click: function(inSender) {
	  try {
                if(this.ExistLogin.getDataValue()==null){return app.alert("Existing Login is not selected");}
                if(this.groupid.getDataValue()==null){return app.alert("Group is not selected");}
                if(this.username.getDataValue()==null){return app.alert("Username is not selected");}
                this.loginPerFrm.operation="update"; 
                
                this.userName.setValue("dataValue",this.ExistLogin.getDisplayValue());
                var count=this.LoginCombo.getCount();
                for(var i=0;i<count;i++)
                {
                    var record=this.LoginCombo.getData()[i];
                    if(this.userName.getDataValue()== record.name && this.ExistLogin.getDataValue() != record.id)
                    {
                        if(this.username.getDataValue()== record.username)
                        {
                            this.username.focus();
                            return app.alert("Username is not available");
                            break;
                        }
                        return app.alert("Duplicate Entry Found with '"+record.name+"'");
                        break;
                    }
                
                }
             
             count=this.getExtLogin.getCount();
             for(var i=0;i<count;i++){
                var record=this.getExtLogin.getData()[i];
                if(record.username==this.username.getDataValue() && this.ExistLogin.getDataValue()!=record.id)
                {
                      this.username.focus();
                        this.userName.clear();
                      return app.alert("Username is not available");
                     break;
                 }
             }
           //alert(this.lblPwd.caption);
           var cap=this.lblDigit.caption;
          // alert(cap);
           if(cap != "85%" && cap != "100%"){
              return app.alert("You need to score at least 85%.<br>Your Password is Not Secure & Could be Compromised.<br>Use a Combination of 10+ Upper & Lower Case Letters, Numbers & Symbols.");
           }
            this.loginPerFrm.updateData();
        } catch(e) {
		  console.error('ERROR IN setLogExistLoginSave2Click: ' + e); 
	  } 
  },
  setLogExistLoginDelete2Click: function(inSender) {
      try {
		  this.loginPerFrm.operation="delete";
          if(this.ExistLogin.getDataValue()==null){return app.alert("Existing Login is not selected");}
          this.loginDeleteDialog.show();
          //this.loginPerFrm.deleteData();
        } catch(e) {
		  console.error('ERROR IN setLogExistLoginDelete2Click: ' + e); 
	  } 
  },
  //Developer Comments:--Event handler to check success of Database Transaction.
  loginPerFrmSuccess: function(inSender, inData) {
	  try {
          
          this.LoginCombo.update();
          var op=this.loginPerFrm.operation;
          if(op=="insert")
          {
              this.ExistLogin.setValue("restrictValues",false);
              var uname=this.userName.getDataValue();
              //this.ExistLogin.setDataValue(inData.id);
              this.ExistLogin.setDisplayValue(uname);
              this.hiddenLUserId.setDataValue(this.Userid.getValue("dataValue"));
              this.panel39.setShowing(true);
              this.setLogCreateLoginNew2.setShowing(true);
              this.setLogExistLoginSave2.setShowing(true);
              this.setLogExistLoginDelete2.setShowing(true);
              
          }
          else if(op =="update")
          {
              app.alert("Data Updated Successfully");
              this.getExtLogin.update();
              this.loginPerFrm.clearData();
              this.hiddenLUserId.setDataValue(this.Userid.getValue("dataValue"));
              this.panel39.setShowing(false);
              this.setLogExistLoginSave2.setShowing(false);
              this.setLogExistLoginDelete2.setShowing(false);
              alpha=0;
              digit=0;
              char=0;
              testPwd=0;            
              len=0;
              
          }
          else if (op=="delete")
          {
              app.alert("Data Deleted successfully");
              this.getExtLogin.update();
              this.hiddenLUserId.setDataValue(this.Userid.getValue("dataValue"));
              this.panel39.setShowing(false);
              this.setLogExistLoginSave2.setShowing(false);
              this.setLogExistLoginDelete2.setShowing(false);
          }
          score=0;
          this.setLoginPermStrengthLabel2.setValue("showing",false);
          this.lblPwd.setValue("showing",false);
         /* app.alert("Data saved successfully");
          
          this.getExtLogin.update();
          this.LoginCombo.update();*/
       
         } catch(e) {
		  console.error('ERROR IN loginPerFrmSuccess: ' + e); 
	  } 
  },
  ExistLoginChange: function(inSender) {
	  try {
        /*  if(this.ExistLogin.getDisplayValue() == ""){
              
              this.panel39.setShowing(false);
              this.groupid.clear();
              this.username.clear();
              this.password.clear();
              this.ips.clear();
          }
          else{*/
              
        		  var selectedId=this.ExistLogin.selectedItem.getValue("id");
                  //alert(selectedId);
                  var count=this.LoginCombo.getCount();
                    for(var i=0;i<count;i++){
                        var record=this.LoginCombo.getData()[i];
                        if(selectedId==record.id){
                             
                             this.userName.setDataValue(record.name);
                             this.groupid.setDataValue(record.groupid);
                             this.username.setDataValue(record.username);
                             this.password.setDataValue(record.password);
                             this.ips.setDataValue(record.ips);
                             var ccount=this.GroupCombo.getCount();
                             for(var j=0;j<ccount;j++)
                             {  
                                 var grecord=this.GroupCombo.getData()[j];
                                 if(record.groupid==grecord.id)
                                 {
                                   this.groupid.setDisplayValue(grecord.name);
                                   break;
                                     
                                 }
                                 
                             }
                             var identifyUser=this.user_Permissions.getData()[0].settings;
                             if(identifyUser=="enabled_modify"){
                            
                             this.panel39.setShowing(true);
                             this.setLogCreateLoginNew2.setShowing(true);
                             this.setLogExistLoginSave2.setShowing(true);
                             this.setLogExistLoginDelete2.setShowing(true);
                             }
                             if(identifyUser=="enabled"){
                                 this.panel39.setShowing(true);
                                 //this.setLogCreateLoginNew2.setShowing(false);
                                 this.setLogExistLoginSave2.setShowing(false);
                                 this.setLogExistLoginDelete2.setShowing(false);
                             }
                             
                             this.userName.clear();
                             this.LogPanel6.setValue("showing",false);
                        }
                    }
          //}--end of else 
		  
	  } catch(e) {
		  console.error('ERROR IN ExistLoginChange: ' + e); 
	  } 
  },
  userNameChange: function(inSender) {
       try {
          
        /*  if(this.userName.getDataValue()!= null)
          {this.panel39.setShowing(true);}
          else
          {this.panel39.setShowing(false);}*/
         
     } catch(e) {
    	  console.error('ERROR IN userNameBlur: ' + e); 
	  } 
  },
   ExistLoginBlur: function(inSender) {
      try {
		  
		  /*if(this.ExistLogin.getDataValue()!=null)
           { this.panel39.setShowing(true); }
           else
           {    if(this.userName.getDataValue()!=null)
                {
                    this.setLogCreateLoginNew2.setShowing(true);
                     this.setLogExistLoginSave2.setShowing(false);
                     this.setLogExistLoginDelete2.setShowing(false);
                }
                else
                {
                    this.panel39.setShowing(false);
                    this.setLogCreateLoginNew2.setShowing(true);
                    this.setLogExistLoginSave2.setShowing(false);
                    this.setLogExistLoginDelete2.setShowing(false);
                    this.loginPerFrm.celarData();
                }
           }*/
	  } catch(e) {
		  console.error('ERROR IN ExistLoginBlur: ' + e); 
	  } 
  },
  passwordFocus: function(inSender) {
      try {
                testPwd=0;
                alpha=0;
                digit=0;
                char=0;
                
                if(this.password.getDataValue() != null){
                 alpha=0;
                 char=0;
                 digit=0;
                 testPwd=0;
                 var desc = new Array();
                 desc[0] ="20%";// "Very Weak";
                 desc[1] = "30%";//"Weak";
                 desc[2] = "50%";//"Medium";
                 desc[3] = "70%";//"Better";
                 desc[4] = "85%";//"Strong";
                 desc[5] = "100%";//"Strongest";
                  alpha=0;
                  char=0;
                  digit=0;
          
                   var data=new String(this.password.getDataValue());
                   //alert("data="+data);
                   var len=data.length;
                   for(var j=0;j<len;j++){
                           value=data.charAt(j);
                           //alert("value="+value);
                           if(value != null){
                                if ( ( value.match(/[a-z]/) ) || ( value.match(/[A-Z]/) ) ) {alpha++;}
                                if ( value.match(/\d+/)) { digit++; } 
                                if ( value.match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) {char++;}
                                
                           }
                           else{
                                if ( ( value.match(/[a-z]/) ) || ( value.match(/[A-Z]/) ) ) {alpha--;}
                                if ( value.match(/\d+/)) { digit--; } 
                                if ( value.match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) {char--;}
                               
                           }
                   }
                   //alert("alpha"+alpha);
                   //alert("digit"+digit);
                   //alert("char"+char);
                 testPwd= alpha+digit+char;
                 //alert("1="+testPwd);
                 if(testPwd<5){//for very week-- 20
                     score=0;
                     this.lblColor.domNode.style.background="#cccccc";
                     this.lblColor.setWidth("20px");
                }
                if(testPwd  >= 5){//for week
                        if( (alpha != 0) && (digit == 0) && (char == 0)){
                            //alert("1"+testPwd);
                           score=1;
                           this.lblColor.domNode.style.background="#ff0000";
                           this.lblColor.setWidth("30px");
        
                        }
                        if( (alpha == 0) && (digit != 0) && (char == 0)){
                           // alert("hi");
                            score=1;
                            this.lblColor.domNode.style.background="#ff0000";
                            this.lblColor.setWidth("30px");
        
                        }
                        if( (alpha == 0) && (digit == 0) && (char != 0)){
                           // alert("hi");
                            score=1;
                            this.lblColor.domNode.style.background="#ff0000";
                            this.lblColor.setWidth("30px");
        
                        }
               }
               //for Medium 30
               if(testPwd  >= 6  && testPwd<=7){
                        if( (alpha != 0) && (digit != 0) && (char == 0)){
                             score=2;
                             this.lblColor.domNode.style.background="#FFFF00";
                             this.lblColor.setWidth("50px");
                        }
                         if( (alpha != 0) && (digit == 0) && (char != 0)){
                             score=2;
                            
                             this.lblColor.domNode.style.background="#FFFF00";
                             this.lblColor.setWidth("50px");
                        }
                        if( (alpha == 0) && (digit != 0) && (char != 0)){
                             score=2;
                            
                             
                             this.lblColor.domNode.style.background="#FFFF00";
                             this.lblColor.setWidth("50px");
                        }
                        //for Medium
                        if( (alpha != 0) && (digit != 0) && (char != 0)){
                             score=3;
                            
                             
                             this.lblColor.domNode.style.background="#87CEEB";
                             this.lblColor.setWidth("65px");
                        }
               }
               //for Better  50
               if(testPwd  >= 8 && testPwd <10){
                        if( (alpha != 0) && (digit != 0) && (char == 0)){
                             score=3;
                           
                             
                             this.lblColor.domNode.style.background="#87CEEB";
                             this.lblColor.setWidth("65px");
                        }
                         if( (alpha != 0) && (digit == 0) && (char != 0)){
                             score=3;
                          
                             
                             this.lblColor.domNode.style.background="#87CEEB";
                             this.lblColor.setWidth("65px");
                        }
                        if( (alpha == 0) && (digit != 0) && (char != 0)){
                            score=3;
                           
                           
                             this.lblColor.domNode.style.background="#87CEEB";
                             this.lblColor.setWidth("65px");
                        }
                        //for Medium
                        if( (alpha != 0) && (digit != 0) && (char != 0)){
                             score=3;
                            
                             
                             this.lblColor.domNode.style.background="#87CEEB";
                             this.lblColor.setWidth("65px");
                        }
               }
               //for Strong 70
               if(testPwd  >= 10 && testPwd <= 15){
                       if( (alpha != 0) && (digit != 0) && (char == 0)){
                             score=4;
                           
                            
                             this.lblColor.domNode.style.background="#48D1CC";
                             this.lblColor.setWidth("70px");
                        }
                         if( (alpha != 0) && (digit == 0) && (char != 0)){
                             score=4;
                               
                             this.lblColor.domNode.style.background="#48D1CC";
                             this.lblColor.setWidth("70px");
                        }
                        if( (alpha == 0) && (digit != 0) && (char != 0)){
                            score=4;
                           
                             this.lblColor.domNode.style.background="#48D1CC";
                             this.lblColor.setWidth("70px");
                        }
                        //for Medium
                        if( (alpha != 0) && (digit != 0) && (char != 0)){
                             score=4;
                             
                            
                             this.lblColor.domNode.style.background="#48D1CC";
                             this.lblColor.setWidth("70px");
                        }
               }
               
               //for storgest--100
                 
               if(testPwd  >= 15){
                   /*    if( (alpha != 0) && (digit != 0) && (char == 0)){
                             score=3;
                           
                            
                             this.lblColor.domNode.style.background="#56e500";
                             this.lblColor.setWidth("80px");
                        }
                         if( (alpha != 0) && (digit == 0) && (char != 0)){
                             score=3;
                               
                             this.lblColor.domNode.style.background="#56e500";
                             this.lblColor.setWidth("80px");
                        }
                        if( (alpha == 0) && (digit != 0) && (char != 0)){
                            score=3;
                           
                             this.lblColor.domNode.style.background="#56e500";
                             this.lblColor.setWidth("80px");
                        }*/
                        //for Medium
                        if( (alpha != 0) && (digit != 0) && (char != 0)){
                             score=5;
                             
                            
                             this.lblColor.domNode.style.background="#399800";
                             this.lblColor.setWidth("100px");
                        }
                        else{
                                     
                                     
                                     
                                    if( (alpha != 0) && (digit != 0) && (char == 0)){
                                        score=4;
                                        this.lblColor.domNode.style.background="#48D1CC";
                                        this.lblColor.setWidth("70px");
                                    }
                                     if( (alpha != 0) && (digit == 0) && (char != 0)){
                                         score=4;
                                         this.lblColor.domNode.style.background="#48D1CC";
                                         this.lblColor.setWidth("70px");
                                    }
                                    if( (alpha == 0) && (digit != 0) && (char != 0)){
                                        score=4;
                                        this.lblColor.domNode.style.background="#48D1CC";
                                        this.lblColor.setWidth("70px");
                                    }
                        }
               }
               
                this.lblDigit.setCaption(desc[score]); 
          }
           this.setLoginPermStrengthLabel2.setValue("showing",true);
           this.LogPanel6.setValue("showing",true);
           this.lblPwd.domNode.style.background="#C0C0C0";
           
  
		  
	  }
	   catch(e) {
		  console.error('ERROR IN passwordFocus: ' + e); 
	  } 
  },
 passwordChange: function(inSender) {
      try {
                
         // array for label
         var desc = new Array();
         desc[0] ="20%";// "Very Weak";
         desc[1] = "30%";//"Weak";
         desc[2] = "50%";//"Medium";
         desc[3] = "70%";//"Better";
         desc[4] = "85%";//"Strong";
         desc[5] = "100%";//"Strongest";
         
         
         if(this.password.getDataValue() == null ){
             this.lblColor.domNode.style.background="#FFFFFF";
             this.lblColor.setWidth("100px");
             this.lblDigit.setCaption("0%"); 
         }
         else{
                        alpha=0;
                        char=0;
                        digit=0;
                        testPwd=0;
                        var data=new String(this.password.getDataValue());
                        var len=data.length;
                        for(var j=0;j<len;j++){
                           value=data.charAt(j);
                           //alert("value="+value);
                           if(value != null){
                                if ( ( value.match(/[a-z]/) ) || ( value.match(/[A-Z]/) ) ) {alpha++;}
                                if ( value.match(/\d+/)) { digit++; } 
                                if ( value.match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) {char++;}
                                
                           }
                           else{
                                if ( ( value.match(/[a-z]/) ) || ( value.match(/[A-Z]/) ) ) {alpha--;}
                                if ( value.match(/\d+/)) { digit--; } 
                                if ( value.match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) {char--;}
                               
                           }
                   }
                        //var testPwd=0;
                        
                        testPwd= alpha+digit+char;
                        //alert("2="+testPwd);
                        var testPer=(testPwd*100)/20;
                        
                        if(testPwd<5){//for very week-- 20
                             score=0;
                             this.lblColor.domNode.style.background="#cccccc";
                             this.lblColor.setWidth("20px");
                        }
                        if(testPwd  >= 5){//for week
                                if( (alpha != 0) && (digit == 0) && (char == 0)){
                                   // alert("2"+testPwd);
                                   score=1;
                                   this.lblColor.domNode.style.background="#ff0000";
                                   this.lblColor.setWidth("30px");
                
                                }
                                if( (alpha == 0) && (digit != 0) && (char == 0)){
                                   // alert("hi");
                                    score=1;
                                    this.lblColor.domNode.style.background="#ff0000";
                                    this.lblColor.setWidth("30px");
                
                                }
                                if( (alpha == 0) && (digit == 0) && (char != 0)){
                                   // alert("hi");
                                    score=1;
                                    this.lblColor.domNode.style.background="#ff0000";
                                    this.lblColor.setWidth("30px");
                
                                }
                       }
                       //for Medium 30
                       if(testPwd  >= 6  && testPwd<=7){
                                if( (alpha != 0) && (digit != 0) && (char == 0)){
                                     score=2;
                                     this.lblColor.domNode.style.background="#FFFF00";
                                     this.lblColor.setWidth("50px");
                                }
                                 if( (alpha != 0) && (digit == 0) && (char != 0)){
                                     score=2;
                                    
                                     this.lblColor.domNode.style.background="#FFFF00";
                                     this.lblColor.setWidth("50px");
                                }
                                if( (alpha == 0) && (digit != 0) && (char != 0)){
                                     score=2;
                                    
                                     
                                     this.lblColor.domNode.style.background="#FFFF00";
                                     this.lblColor.setWidth("50px");
                                }
                                //for Medium
                                if( (alpha != 0) && (digit != 0) && (char != 0)){
                                     score=3;
                                    
                                     
                                     this.lblColor.domNode.style.background="#87CEEB";
                                     this.lblColor.setWidth("65px");
                                }
                       }
                       //for Better  50
                       if(testPwd  >= 8 && testPwd <10){
                                if( (alpha != 0) && (digit != 0) && (char == 0)){
                                     score=3;
                                   
                                     
                                     this.lblColor.domNode.style.background="#87CEEB";
                                     this.lblColor.setWidth("65px");
                                }
                                 if( (alpha != 0) && (digit == 0) && (char != 0)){
                                     score=3;
                                  
                                     
                                     this.lblColor.domNode.style.background="#87CEEB";
                                     this.lblColor.setWidth("65px");
                                }
                                if( (alpha == 0) && (digit != 0) && (char != 0)){
                                    score=3;
                                   
                                   
                                     this.lblColor.domNode.style.background="#87CEEB";
                                     this.lblColor.setWidth("65px");
                                }
                                //for Medium
                                if( (alpha != 0) && (digit != 0) && (char != 0)){
                                     score=3;
                                    
                                     
                                     this.lblColor.domNode.style.background="#87CEEB";
                                     this.lblColor.setWidth("65px");
                                }
                       }
                       //for Strong 70
                       if(testPwd  >= 10 && testPwd <= 15){
                               if( (alpha != 0) && (digit != 0) && (char == 0)){
                                     score=4;
                                   
                                    
                                     this.lblColor.domNode.style.background="#48D1CC";
                                     this.lblColor.setWidth("70px");
                                }
                                 if( (alpha != 0) && (digit == 0) && (char != 0)){
                                     score=4;
                                       
                                     this.lblColor.domNode.style.background="#48D1CC";
                                     this.lblColor.setWidth("70px");
                                }
                                if( (alpha == 0) && (digit != 0) && (char != 0)){
                                    score=4;
                                   
                                     this.lblColor.domNode.style.background="#48D1CC";
                                     this.lblColor.setWidth("70px");
                                }
                                //for Medium
                                if( (alpha != 0) && (digit != 0) && (char != 0)){
                                     score=4;
                                     
                                    
                                     this.lblColor.domNode.style.background="#48D1CC";
                                     this.lblColor.setWidth("70px");
                                }
                       }
                       
                       //for storgest--100
                         
                       if(testPwd  >= 15){
                           /*    if( (alpha != 0) && (digit != 0) && (char == 0)){
                                     score=3;
                                   
                                    
                                     this.lblColor.domNode.style.background="#56e500";
                                     this.lblColor.setWidth("80px");
                                }
                                 if( (alpha != 0) && (digit == 0) && (char != 0)){
                                     score=3;
                                       
                                     this.lblColor.domNode.style.background="#56e500";
                                     this.lblColor.setWidth("80px");
                                }
                                if( (alpha == 0) && (digit != 0) && (char != 0)){
                                    score=3;
                                   
                                     this.lblColor.domNode.style.background="#56e500";
                                     this.lblColor.setWidth("80px");
                                }*/
                                //for Medium
                                if( (alpha != 0) && (digit != 0) && (char != 0)){
                                     score=5;
                                     
                                    
                                     this.lblColor.domNode.style.background="#399800";
                                     this.lblColor.setWidth("100px");
                                }
                                else{
                                     
                                     
                                     
                                    if( (alpha != 0) && (digit != 0) && (char == 0)){
                                        score=4;
                                        this.lblColor.domNode.style.background="#48D1CC";
                                        this.lblColor.setWidth("70px");
                                    }
                                     if( (alpha != 0) && (digit == 0) && (char != 0)){
                                         score=4;
                                         this.lblColor.domNode.style.background="#48D1CC";
                                         this.lblColor.setWidth("70px");
                                    }
                                    if( (alpha == 0) && (digit != 0) && (char != 0)){
                                        score=4;
                                        this.lblColor.domNode.style.background="#48D1CC";
                                        this.lblColor.setWidth("70px");
                                    }
                                }
                       }
                       
                        this.lblDigit.setCaption(desc[score]);  
                       // this.lblDigit.setCaption(testPwd+"%");             
                        //this.lblPwd.domNode.style.color = "red";           
         }
      } catch(e) {
          console.error('ERROR IN passwordChange: ' + e); 
      } 
  },
  passwordBlur: function(inSender) {
      try{
            this.LogPanel6.setValue("showing",false);   
       } catch(e) {
		  console.error('ERROR IN passwordBlur: ' + e); 
	  } 
  },
ipsBlur: function(inSender) {
      try {
            var ips=this.ips.getDataValue();
            if(ips!=null)
            {   
                var iplist=0;
                var cips="";
               ips=ips.replace(/ /g, ",");
               ips=ips.replace(/\n/g, ",");
               if(ips.match(/,/gi))
               {
                var newips=ips.split(",");
                cips=newips[0];
                for(var i=1;i<newips.length;i++)
                {
                   if(newips[i]!="")
                   {cips=cips+","+newips[i];}
                }
                ips=cips;
                this.ips.setDataValue(ips);
                this.ips.setDisplayValue(ips);
                
                  iplist=ips.split(",");
                  for(var i=0;i<iplist.length;i++)
                  {
                      var aip=iplist[i];
                      if(aip.match(/./gi))
                      {
                         var myips=aip.split(".");
                         if(myips.length != 4)
                         {if(ips != null){ this.ips.clear(); return;}}
                         else
                         {
                            if( myips[0] <= 255){
                               if( myips[1] <= 255){
                                   if( myips[2] <= 255){
                                       if( myips[3] <= 255){ }
                                       else{ 
                                             if(ips != null){this.ips.clear(); return;}
                                        }
                                    }else{
                                            if(ips != null){this.ips.clear(); return;}
                                    }
                                }else{
                                        if(ips != null){this.ips.clear(); return;}
                                }
                            }else{
                                    if(ips != null){this.ips.clear(); return;}
                            }
                          }
                        }
                    }
                }    
                else
                {
                   var ips=this.ips.getDataValue();
                   if(ips.match(/./gi))
                   {
                       var myips=ips.split(".");
                       if(myips.length != 4){
                         if(ips != null){this.ips.clear(); return;}
                       }else{
                         if( myips[0] <= 255){
                             if( myips[1] <= 255){
                                 if( myips[2] <= 255){
                                     if( myips[3] <= 255){}
                                     else{ 
                                         if(ips != null){this.ips.clear(); return;}
                                     }
                                 }else{
                                    if(ips != null){this.ips.clear(); return;}
                                 }
                             }else{
                                if(ips != null){this.ips.clear(); return;}
                             }
                         }else{
                             if(ips != null){this.ips.clear(); return;}
                         }
                     }
                   }
                }
            }
                
      } catch(e) {
          //app.alert("IP address is not valid");      
    	  //console.error('ERROR IN ipsBlur: ' + e); 
	  } 
  },
 
  userGroupIdResult: function(inSender, inDeprecated) {
	  try {
          permission_group_id=inSender.getData()[0].dataValue;
          this.user_Permissions.update();
	  } catch(e) {
		  console.error('ERROR IN userGroupIdResult: ' + e); 
	  } 
  },
  user_PermissionsSuccess: function(inSender, inDeprecated) {
	  try {
		 // alert(inSender.getItem(0).data.settings);
		  
       
         if(inSender.getItem(0).data.settings == "enabled")
         {  this.layerSettings.setShowing(true);
            this.setGrpCreateGrpPanel4.setShowing(false);
            this.setGrpExistGrpSave4.setShowing(false);
            this.setGrpExistGrpDelete4.setShowing(false);
            this.LogPanel1.setShowing(false);
            this.setLogExistLoginSave2.setShowing(false);
            this.setLogExistLoginDelete2.setShowing(false);
         }
         if(inSender.getItem(0).data.settings == "enabled_modify")
         {
           // alert("call1");  
            this.layerSettings.setShowing(true);
            //alert("call2");
            this.setGrpCreateGrpPanel4.setShowing(true);
            //this.setGrpExistGrpSave4.setShowing(true);
            //this.setGrpExistGrpDelete4.setShowing(true);
            this.LogPanel1.setShowing(true);
            //this.setLogExistLoginSave2.setShowing(true);
            //this.setLogExistLoginDelete2.setShowing(true);
        }
         
          if(inSender.getItem(0).data.home == "disabled")
          {this.layerHome.setShowing(false);}
          if(inSender.getItem(0).data.settings == "disabled")
          {this.layerSettings.setShowing(false);}
          if(inSender.getItem(0).data.subscriptions == "disabled")
          {this.layerSubscriptions.setShowing(false);}
          if(inSender.getItem(0).data.authsmtp == "disabled")
          {this.layerAuthsmtp.setShowing(false);}
          if(inSender.getItem(0).data.spamscore == "disabled")
          {this.tabLayerSpamScore.setShowing(false);}
          if(inSender.getItem(0).data.emaileditor == "disabled")
          {this.tabLayerEmailEditor.setShowing(false);}
          if(inSender.getItem(0).data.emaildelivery == "disabled")
          {this.tabLayerEmailDelivery.setShowing(false);}
          if(inSender.getItem(0).data.webmail == "disabled")
          {this.tabLayerWebmail.setShowing(false);}
          if(inSender.getItem(0).data.bulkmarketing == "disabled")
          {this.layerBulkMarketing.setShowing(false);}
          
        } catch(e) {
		  console.error('ERROR IN user_PermissionsSuccess: ' + e); 
	  } 
  },
   
  LoginComboSuccess: function(inSender, inDeprecated) {
	  try {
    		  this.ExistLogin.setValue("restrictValues",true);
    		  
    	  } catch(e) {
    		  console.error('ERROR IN LoginComboSuccess: ' + e); 
    	  } 
      },
      
  loginDeleteDialogButton1Click: function(inSender, inButton, inText) {
	  try {
                this.loginPerFrm.deleteData();		  
		       
	  } catch(e) {
		  console.error('ERROR IN loginDeleteDialogButton1Click: ' + e); 
	  } 
  },
 
  
  
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------  
                //=============================SUBSCRIPTION LAYAR
 
  subTransLogDojoGridC3Format: function( inValue, rowId, cellId, cellField, cellObj, rowObj) {
	  try {
            //var value=inValue;
            //alert("starting-----"+inValue+" "+rowId);
            var digit=inValue;
            if(digit=="0"){
               return "Purchased";
            }
            else{
               return "Subscribed";
            }
      } catch(e) {
		  console.error('ERROR IN subTransLogDojoGridC3Format: ' + e); 
	  } 
  },
  subTransLogDojoGridC2Format: function( inValue, rowId, cellId, cellField, cellObj, rowObj) {
	  try {
             var dt=new Date(inValue);
             return dojo.date.locale.format(dt, {selector: "date", datePattern: "dd/MMM/yyyy"});		  
		  
	  } catch(e) {
		  console.error('ERROR IN subTransLogDojoGridC2Format: ' + e); 
	  } 
  },
  subTransLogDojoGridC4Format: function( inValue, rowId, cellId, cellField, cellObj, rowObj) {
	  try {
          //alert(inValue);
          var exdt=new Date(inValue);
          return dojo.date.locale.format(exdt, {selector: "date", datePattern: "dd/MMM/yyyy"});		  
		  
	  } catch(e) {
		  console.error('ERROR IN subTransLogDojoGridC4Format: ' + e); 
	  } 
  },
 
  layerSubscriptionsShow: function(inSender) {
	  try {
                //refresh layer
                
                  this.SubscriptionsTB.update();
                  this.AccountInfoService.update();
                  this.TransactionsTB.update();
                  this.ProdcutPlansTB.update();
                  this.subscriptionTabGrid.update();
                  this.serviceLoadingImg.update();
                
		  
	  } catch(e) {
		  console.error('ERROR IN layerSubscriptionsShow: ' + e); 
	  } 
  },
  

  layerSettingsShow: function(inSender) {//for the hidden field need to update the service variable
	  try {
             this.myUserID.update();
             this.myUserIdQuery.update();
     } catch(e) {
		  console.error('ERROR IN layerSettingsShow: ' + e); 
	  } 
  },
  subscriptionTabGridSuccess: function(inSender, inDeprecated) {
	  try {
           this.AccountInfoService.update();
          var count=this.subscriptionTabGrid.getCount();  
                //AuthSMTP-----------------------------------------------------------------
                for(var i=0;i<count;i++)
                {
                    //alert(count);
                    var record=this.subscriptionTabGrid.getData()[i];
                    
                    if(record.c6 >=1 && record.c6 <=4){
                        this.subAuthsmtpProduct.setReadonly(true);
                        //for cancel button
                        if(record.c5 == 1){
                            //alert(record.c5)
                            //this.subAuthsmtpCancel.setValue("showing",true);
                            this.subAuthsmtpCancel.setShowing(true);
                        }
                        else{
                                //alert(record.c5)
                                //this.subAuthsmtpCancel.setValue("showing",false);
                                this.subAuthsmtpCancel.setShowing(false);
                        }
                        
                        //for the status
                        if(record.c3==true){
                            //this.subAuthsmtpStatus.setDisplayValue("Subscribed");
                            this.subAuthsmtpStatus.setDataValue("Subscribed");
                        }
                        else{
                           // this.subAuthsmtpStatus.setDisplayValue("purchased");
                            this.subAuthsmtpStatus.setDataValue("purchased");
                        }
                        
                        //for expired
                        var currentdt=new Date();
                        var expireDt=new Date(record.c4);
                        if(currentdt<expireDt){//not expired yet
                               //alert(expireDt);
                                var year=expireDt.getFullYear();
                                //alert("year"+year);
                                var dt=expireDt.getDate();
                                //alert("dt"+dt);
                                var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                //alert("month"+month[expireDt.getMonth()]);
                                var mmm=month[expireDt.getMonth()];
                                this.subAuthsmtpExpires.setDataValue(dt+"/"+mmm+"/"+year);
                                this.subAuthsmtpProduct.setReadonly(true);
                                
                                
                                 
                            }
                            else{
                                 this.subAuthsmtpProduct.setReadonly(false);
                                 this.subAuthsmtpExpires.setDataValue("Expired");
                                 
                                /*  //set diff panel showing ture
                                this.panel50.setShowing(false);
                                this.panel51.setShowing(false);
                                this.panel52.setShowing(false);
                                this.authsmtpHelp.setShowing(true);*/
                            }
                            
                            //--for subAuthsmtpProduct---------
                            
                            var authsmtpCount=this.authsmtpProductWMV.getCount();
                            for(var j=0;j<authsmtpCount;j++)
                            {
                                var authsmtpRecord=this.authsmtpProductWMV.getData()[j];
                                if(authsmtpRecord.dataValue == record.c6){
                                   // alert("=======================================");
                                    this.subAuthsmtpProduct.setDisplayValue(authsmtpRecord.name);
                                    //for the price
                                    var displayValue=this.subAuthsmtpProduct.setDisplayValue(authsmtpRecord.name);
                                    break;
                                }
                           }
                           break;
                        
                     }
                      else{//No record found
                          this.subAuthsmtpProduct.setReadonly(false);
                          this.subAuthsmtpStatus.setDataValue("None");
                          this.subAuthsmtpExpires.setDataValue("N/A");
                          
                           //set diff panel showing ture
                            this.panel50.setShowing(false);
                            this.panel51.setShowing(false);
                            this.panel52.setShowing(false);
                            this.authsmtpHelp.setShowing(true);
                     }
                    
                }
//----------------------------------------------------------for bulkmarketing--------------------------------------------------------------------------
                 for(var i=0;i<count;i++)
                 {
                    var record=this.subscriptionTabGrid.getData()[i];
                     
                     if(record.c6 >=6 && record.c6 <=21){
                            this.subBulkMarkProduct.setReadonly(true);
                            //for cancel button
                            if(record.c5 == 1){
                                this.subBulkMarkCancel.setValue("showing",true);
                            }
                            else{this.subBulkMarkCancel.setValue("showing",false);}
                            //for the status
                            if(record.c3==true){
                                //this.subBulkMarkStatus.setDisplayValue("Subscribed");
                                this.subBulkMarkStatus.setDataValue("Subscribed");
                            }
                            else{
                               // this.subBulkMarkStatus.setDisplayValue("purchased");
                                this.subBulkMarkStatus.setDataValue("purchased");
                            }
                        //for expired
                        var currentdt=new Date();
                        var expireDt=new Date(record.c4);
                        if(currentdt<expireDt){//not expired yet
                                //alert(expireDt);
                                var year=expireDt.getFullYear();
                                //alert("year"+year);
                                var dt=expireDt.getDate();
                                //alert("dt"+dt);
                                var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                //alert("month"+month[expireDt.getMonth()]);
                                var mmm=month[expireDt.getMonth()];
                                this.subBulkMarkExpires.setDataValue(dt+"/"+mmm+"/"+year);
                                this.subBulkMarkProduct.setReadonly(true);
                            }
                            else{//expire
                                // alert("in");
                                this.subBulkMarkProduct.setReadonly(false);
                                this.subBulkMarkExpires.setDataValue("Expired");
                            }
                            //--for bulckmarketingProduct---------
                            
                            var bulkmarkProductCount=this.bulkmarkProductWMV.getCount();
                            for(var j=0;j<bulkmarkProductCount;j++)
                            {
                                var bulkmarkRecord=this.bulkmarkProductWMV.getData()[j];
                                if(bulkmarkRecord.dataValue == record.c6){
                                   // alert("=======================================");
                                    this.subBulkMarkProduct.setDisplayValue(bulkmarkRecord.name);
                                    break;
                                }
                           }
                           break;
                     }
                     else{
                         this.subBulkMarkProduct.setReadonly(false);
                         this.subBulkMarkStatus.setDataValue("None");
                         this.subBulkMarkExpires.setDataValue("N/A");
                    }
                }
                    
//--------for subSpamScor--------------------------------------------------------------------------
                 for(var i=0;i<count;i++)
                {
                   var record=this.subscriptionTabGrid.getData()[i];
                   if(record.c6 >=30 && record.c6 <=36){
                           this.subSpamScorProduct.setReadonly(true);
                           //for cancel button
                            if(record.c5 == 1){
                                this.subSpamScorCancel.setValue("showing",true);
                            }
                            else{this.subSpamScorCancel.setValue("showing",false);}
                            //for the status
                            if(record.c3==true){
                               // this.subSpamScorStatus.setDisplayValue("Subscribed");
                                this.subSpamScorStatus.setDataValue("Subscribed");
                            }
                            else{
                                // this.subSpamScorStatus.setDisplayValue("purchased");
                                 this.subSpamScorStatus.setDataValue("purchased");
                            }
                        //for expired
                        var currentdt=new Date();
                        var expireDt=new Date(record.c4);
                        if(currentdt<expireDt){//not expired yet
                                //alert(expireDt);
                                var year=expireDt.getFullYear();
                                //alert("year"+year);
                                var dt=expireDt.getDate();
                                //alert("dt"+dt);
                                var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                //alert("month"+month[expireDt.getMonth()]);
                                var mmm=month[expireDt.getMonth()];
                                this.subSpamScorExpires.setDataValue(dt+"/"+mmm+"/"+year);
                                this.subSpamScorProduct.setReadonly(true);
                                
                            }
                            else{
                                 this.subSpamScorProduct.setReadonly(false);
                                 this.subSpamScorExpires.setDataValue("Expired");
                            }
                            //--for subSpamScorProduct---------
                            
                            var spamscoreCount=this.spamscoreProductWMV.getCount();
                            for(var j=0;j<spamscoreCount;j++)
                            {
                                
                                var spamscoreRecord=this.spamscoreProductWMV.getData()[j];
                                if(spamscoreRecord.dataValue == record.c6){
                                   // alert("=======================================");
                                    this.subSpamScorProduct.setDisplayValue(spamscoreRecord.name);
                                    break;
                                }
                           }
                           break;
                   }
                   else{
                       this.subSpamScorProduct.setReadonly(false);
                       //this.subSpamScorStatus.setDataValue("Not Available Yet");
                       //this.subSpamScorExpires.setDataValue("N/A");
                  }
                }
                  
 //for the Email Editor-------------------------------------------
                   for(var i=0;i<count;i++)
                   {
                          var record=this.subscriptionTabGrid.getData()[i];
                          if(record.c6 == 29){
                              this.subEmailEdProduct.setReadonly(true);
                              //for cancel button---------
                                if(record.c5 == 1){
                                  
                                    this.subEmailEdCancel.setValue("showing",true);
                                }
                                else{this.subEmailEdCancel.setValue("showing",false);}
                                 //for the status-----
                                if(record.c3==true){
                                    //this.subAuthsmtpStatus.setDisplayValue("Subscribed");
                                    this.subEmailEdStatus.setDataValue("Subscribed");
                                }
                                else{
                                   // this.subAuthsmtpStatus.setDisplayValue("purchased");
                                    this.subEmailEdStatus.setDataValue("purchased");
                                }
                                //for expired---
                                var currentdt=new Date();
                                var expireDt=new Date(record.c4);
                                if(currentdt<expireDt){//not expired yet
                                       //alert(expireDt);
                                        var year=expireDt.getFullYear();
                                        //alert("year"+year);
                                        var dt=expireDt.getDate();
                                        //alert("dt"+dt);
                                        var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        //alert("month"+month[expireDt.getMonth()]);
                                        var mmm=month[expireDt.getMonth()];
                                        this.subEmailEdExpires.setDataValue(dt+"/"+mmm+"/"+year);
                                        this.subEmailEdProduct.setReadonly(true);
                                    }
                                    else{
                                         this.subEmailEdProduct.setReadonly(false);
                                         this.subEmailEdExpires.setDataValue("Expired");
                                    }
                                    
                                     //--for subEmailEdProduct---------
                                    
                                    var subEmailEd=this.emaileditorProductWMV.getCount();
                                    for(var j=0;j<subEmailEd;j++)
                                    {
                                        var subEmailEdRecord=this.emaileditorProductWMV.getData()[j];
                                        if(subEmailEdRecord.dataValue == record.c6){
                                           // alert("=======================================");
                                            this.subEmailEdProduct.setDisplayValue(subEmailEdRecord.name);
                                            break;
                                        }
                                   }
                                   break;
                          }
                          else{
                              this.subEmailEdProduct.setReadonly(false);
                              this.subEmailEdStatus.setDataValue("Not Available Yet");
                              this.subEmailEdExpires.setDataValue("N/A");
                          }
                }
                  
                  
 //for Email Delivery---------------------------------------------
                 for(var i=0;i<count;i++)
                 {
                     var record=this.subscriptionTabGrid.getData()[i];
                     
                     if(record.c6 >=22 && record.c6 <=28){
                              // alert(record.c6);
                               this.subEmailDelProduct.setReadonly(true);
                                //for cancel button
                                if(record.c5 == 1){
                                    this.subEmailDelCancel.setValue("showing",true);
                                }
                                else{this.subEmailDelCancel.setValue("showing",false);}
                                
                                 //for the status
                                if(record.c3==true){
                                    //this.subAuthsmtpStatus.setDisplayValue("Subscribed");
                                    this.subEmailDelStatus.setDataValue("Subscribed");
                                }
                                else{
                                   // this.subAuthsmtpStatus.setDisplayValue("purchased");
                                    this.subEmailDelStatus.setDataValue("purchased");
                                }
                               //for expired---
                                var currentdt=new Date();
                                var expireDt=new Date(record.c4);
                                if(currentdt<expireDt){//not expired yet
                                       //alert(expireDt);
                                        var year=expireDt.getFullYear();
                                        //alert("year"+year);
                                        var dt=expireDt.getDate();
                                        //alert("dt"+dt);
                                        var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        //alert("month"+month[expireDt.getMonth()]);
                                        var mmm=month[expireDt.getMonth()];
                                        this.subEmailDelExpires.setDataValue(dt+"/"+mmm+"/"+year);
                                        this.subEmailDelProduct.setReadonly(true);
                                        //alert("call1");
                                    }
                                    else{
                                        this.subEmailDelProduct.setReadonly(false);
                                        this.subEmailDelExpires.setDataValue("Expired");
                                    }
                                    
                                    //--for EmailDeleveryProduct---------
                                    
                                    var EmailDelCount=this.emaildeliveryProductWMV.getCount();
                                    for(var j=0;j<EmailDelCount;j++)
                                    {
                                        var EmailDelRecord=this.emaildeliveryProductWMV.getData()[j];
                                        if(EmailDelRecord.dataValue == record.c6){
                                            this.subEmailDelProduct.setDisplayValue(EmailDelRecord.name);
                                            break;
                                        }
                                    }
                                    break;
                        }
                        else{
                                 //alert("out");
                                 this.subEmailDelProduct.setReadonly(false);
                                 this.subEmailDelStatus.setDataValue("Not Available Yet");
                                 this.subEmailDelExpires.setDataValue("N/A");
                     }
                     
                 }
                 
                 //for webmail---------------
                    for(var i=0;i<count;i++)
                   {
                           var record=this.subscriptionTabGrid.getData()[i];
                           if(record.c6 == 37){  
                               this.subWebmailProduct.setReadonly(true);
                               //for cancel button
                                if(record.c5 == 1){
                                    this.subWebmailCancel.setValue("showing",true);
                                }
                                else{this.subWebmailCancel.setValue("showing",false);}
                                //for the status
                                if(record.c3==true){
                                    this.subWebmailStatus.setDataValue("Subscribed");
                                }
                                else{
                                   this.subWebmailStatus.setDataValue("purchased");
                                }
                                //for expired
                                var currentdt=new Date();
                                var expireDt=new Date(record.c4);
                                //alert(expireDt);
                                if(currentdt<expireDt){//not expired yet
                                       //alert(expireDt);
                                        var year=expireDt.getFullYear();
                                        //alert("year"+year);
                                        var dt=expireDt.getDate();
                                        //alert("dt"+dt);
                                        var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        //alert("month"+month[expireDt.getMonth()]);
                                        var mmm=month[expireDt.getMonth()]
                                        this.subWebmailExpires.setDataValue(dt+"/"+mmm+"/"+year);
                                        this.subWebmailProduct.setReadonly(true);
                                    }
                                    else{
                                         this.subWebmailProduct.setReadonly(false);
                                         this.subWebmailExpires.setDataValue("Expired");
                                    }
                                    //--for subWebmailProduct---------
                                    
                                    var subWebCount=this.webmailProductWMV.getCount();
                                    for(var j=0;j<subWebCount;j++)
                                    {
                                        var subWebRecord=this.webmailProductWMV.getData()[j];
                                        if(subWebRecord.dataValue == record.c6){
                                           this.subWebmailProduct.setDisplayValue(subWebRecord.name);
                                            break;
                                        }
                                   }
                                   break;
                           }
                           else{
                                this.subWebmailProduct.setReadonly(false);
                                this.subWebmailStatus.setDataValue("Not Available Yet");
                                this.subWebmailExpires.setDataValue("N/A");
                           }
                    }    	  
		  
	  } catch(e) {
		  console.error('ERROR IN subscriptionTabGridSuccess: ' + e); 
	  } 
  },
  
//====================================================================================
//for the AuthSMPT Purchse and buy-----------------------------------------------------
  subAuthsmtpBuyClick: function(inSender) {
	  try {
               
                 var subAuthsmtpProductPlanId=this.subAuthsmtpProduct.getDataValue();//productPlanId
                 //alert(subAuthsmtpProductPlanId);
                 var count=this.ProdcutPlansTB.getCount(); 
                 for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     //alert(record.planId);
                     if(record.planId==subAuthsmtpProductPlanId){//Transaction_PlanId=Product_planID
                           //readOnly
                            var readOnlyData=this.subAuthsmtpProduct.readonly;
                            if(readOnlyData==true){//readonly then inset data
                                
                                if(record.price < this.subAccFundBalance.getDataValue()){//sufficient bal
                                    
                                    //default value for hidden field
                                    var count=this.ProdcutPlansTB.getCount(); 
                                    for(var j=0 ; j<count ; j++){
                                         var record=this.ProdcutPlansTB.getData()[j];
                                         //alert(record.planId);
                                         if(record.planId==this.subAuthsmtpProduct.getDataValue()){
                                                      var productPrice=record.price;
                                                      var prodctCr=record.credits;
                                                      var amount=record.amount;
                                                      //alert(amount);
                                                      this.authSMTPprice.setDataValue(productPrice);
                                                      this.authSMTPcredits.setDataValue(prodctCr);
                                                      this.amount.setDataValue(amount);
                                                       var BTrue=true
                                                       this.transactionsRenew.setDataValue(BTrue);
                                                       this.dateTime1.setDataValue(new Date().getTime());
                                                       if(record.subscription){
                                                                  var currentdt=new Date();
                                                                   var yy=currentdt.getFullYear();
                                                                   var year=yy+1;
                                                                   var dt=currentdt.getDate();
                                                                   var month=new Array(12);
                                                                        month[0]="Jan";
                                                                        month[1]="Feb";
                                                                        month[2]="Mar";
                                                                        month[3]="Apr";
                                                                        month[4]="May";
                                                                        month[5]="Jun";
                                                                        month[6]="Jul";
                                                                        month[7]="Aug";
                                                                        month[8]="Sep";
                                                                        month[9]="Oct";
                                                                        month[10]="Nov";
                                                                        month[11]="Dec";
                                                                       // alert(currentdt.getMonth()+1);
                                                                       var mmm=month[currentdt.getMonth()];
                                                                       var dateString=dt+"/"+mmm+"/"+year;
                                                                       var exDate=new Date(dateString);
                                                                       this.exipireDt.setDataValue(exDate);
                                                        }else{
                                                              var currentdt=new Date();
                                                               var yy=currentdt.getFullYear();
                                                               var dt=currentdt.getDate();
                                                               var month=new Array(12);
                                                                    month[0]="Jan";
                                                                    month[1]="Feb";
                                                                    month[2]="Mar";
                                                                    month[3]="Apr";
                                                                    month[4]="May";
                                                                    month[5]="Jun";
                                                                    month[6]="Jul";
                                                                    month[7]="Aug";
                                                                    month[8]="Sep";
                                                                    month[9]="Oct";
                                                                    month[10]="Nov";
                                                                    month[11]="Dec";
                                                                    
                                                                   var mmm=month[currentdt.getMonth()+1];
                                                                   var dateString=dt+"/"+mmm+"/"+yy;
                                                                   var exDate=new Date(dateString);
                                                                   this.exipireDt.setDataValue(exDate);
                                                      }
                                         }
                                    }
                                    //dialog box for read only
                                    this.Dialog_subReadOnlyBye.setUserPrompt(this.subAuthsmtpProduct.getDisplayValue()+" you wish to purchase");
                                    this.Dialog_subReadOnlyBye.show();
                                }
                                else{//not enought balance
                                          this.subscriNotEnoughtbal.show();
                                }
                            }
                            else if(record.price < this.subAccFundBalance.getDataValue()){//for not read only then insert data
                                          var productName=this.subAuthsmtpProduct.getDisplayValue();
                                          this.subscriAuthSMTPbal1.setUserPrompt("Are you sure you want to Buy/Subscribe to the Product "+productName+"<br>This cannot be reversed if you click 'Yes Please'");
                                          this.subscriAuthSMTPbal1.show();
                                            
                                          
                             }
                             else{//not enought balance
                                          this.subscriNotEnoughtbal.show();
                             }
                     }
                 }
                
                
		  
	  } catch(e) {
		  console.error('ERROR IN subAuthsmtpBuyClick: ' + e); 
	  } 
  },

  subAuthsmtpProductChange: function(inSender) {//for the price,credit and renew field set which are hidden
	  try {
          
                var count=this.ProdcutPlansTB.getCount(); 
                for(var j=0 ; j<count ; j++){
                         var record=this.ProdcutPlansTB.getData()[j];
                         //alert(record.planId);
                         if(record.planId==this.subAuthsmtpProduct.getDataValue()){
                              
                              var productPrice=record.price;
                              var prodctCr=record.credits;
                              var amount=record.amount;
                              //alert(amount);
                              this.authSMTPprice.setDataValue(productPrice);
                              this.authSMTPcredits.setDataValue(prodctCr);
                              this.amount.setDataValue(amount);
                              var BTrue=true
                              this.transactionsRenew.setDataValue(BTrue);
                              this.dateTime1.setDataValue(new Date().getTime());
                              if(record.subscription){
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var year=yy+1;
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        //alert(currentdt.getMonth()+1);
                                       var mmm=month[currentdt.getMonth()];
                                       var dateString=dt+"/"+mmm+"/"+year;
                                       var exDate=new Date(dateString);
                                       this.exipireDt.setDataValue(exDate);
                              }else{
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        
                                       var mmm=month[currentdt.getMonth()+1];
                                       var dateString=dt+"/"+mmm+"/"+yy;
                                       var exDate=new Date(dateString);
                                       this.exipireDt.setDataValue(exDate);
                              }
                             
                         }
                }
                
	  } catch(e) {
		  console.error('ERROR IN subAuthsmtpProductChange: ' + e); 
	  } 
  },
  subscriAuthSMTPbal1Button1Click: function(inSender, inButton, inText) {//for form insertion
      try {
              this.liveFrmAuthSmpt.operation="insert";
              this.liveFrmAuthSmpt.insertData();
              
      } catch(e) {
		  console.error('ERROR IN subscriAuthSMTPbal1Button1Click: ' + e); 
	  } 
  },
   Dialog_subReadOnlyByeButton1Click: function(inSender, inButton, inText) {//read only dialog box
      try {
		      this.liveFrmAuthSmpt.operation="insert";
              this.liveFrmAuthSmpt.insertData();
              
        	  
	  } catch(e) {
		  console.error('ERROR IN Dialog_subReadOnlyByeButton1Click: ' + e); 
	  } 
  },
  liveFrmAuthSmptSuccess: function(inSender, inData) {
	  try {
                //alert(this.AccountInfoService.getData()[0].balance);
                //alert(this.authSMTPprice.getDataValue());
                var diff=this.AccountInfoService.getData()[0].balance-this.authSMTPprice.getDataValue();
                this.subAccFundBalance.setDataValue(diff);
                
                
                //updat the account table by query
                this.accounts_balance_authSMPT.input.setValue("bal", diff);
                this.accounts_balance_authSMPT.input.setValue("userId", this.authUserId.getDataValue());
                this.accounts_balance_authSMPT.update();
                //updat the subscriptions table by query
                this.subscriptions_authsmtpActive_authSMPT.input.setValue("authsmtpActive", true);
                this.subscriptions_authsmtpActive_authSMPT.input.setValue("userId", this.authUserId.getDataValue());
                this.subscriptions_authsmtpActive_authSMPT.update();
                
               //set the panel title here
                var registerMailContainerTitle="Register up to "+this.subAuthsmtpProduct.getDisplayValue();
               //alert(registerMailContainerTitle);
                this.registerMailContainer.setValue("title",registerMailContainerTitle);
                
                //set diff panel showing ture
                this.panel50.setShowing(true);
                this.panel51.setShowing(true);
                this.panel52.setShowing(true);
                this.authsmtpHelp.setShowing(false);
                
                
                 //refresh layer
              this.AccountInfoService.update();
              this.TransactionsTB.update();
              this.ProdcutPlansTB.update();
              this.subscriptionTabGrid.update();
               
       } catch(e) {
		  console.error('ERROR IN liveFrmAuthSmptSuccess: ' + e); 
	  } 
  },
  
 //---------------authSmtp CANCEL --------for the CANCEL DIALOG Box operation of the diff renew=0
 
 subAuthsmtpCancelClick: function(inSender) {
      try {
                
                var count=this.TransactionsTB.getCount();
                //alert("coount"+count);
                for(var i=0 ; i<count ; i++){
                    var record=this.TransactionsTB.getData()[i];
                    
                    if(record.planId==this.subAuthsmtpProduct.getDataValue()){
                        //alert(this.subAuthsmtpProduct.getDataValue());
                        var productName=this.subAuthsmtpProduct.getDisplayValue();
                        this.Dilog_subscription_authSMTP_Cancel.setUserPrompt("The subscription for "+productName+" will not be renewed on the expiry date");
                        this.Dilog_subscription_authSMTP_Cancel.show();
                        
                        
             
              
                    }
                }
		  
	  } catch(e) {
		  console.error('ERROR IN subAuthsmtpCancelClick: ' + e); 
	  } 
  },

   Dilog_subscription_authSMTP_CancelButton1Click: function(inSender, inButton, inText) {
      try {
                this.subscriptions_transaction_Cancel_renew.input.setValue("renew",false);
                this.subscriptions_transaction_Cancel_renew.input.setValue("userId",this.authUserId.getDataValue());
                this.subscriptions_transaction_Cancel_renew.input.setValue("planId",this.subAuthsmtpProduct.getDataValue());
                this.subscriptions_transaction_Cancel_renew.update
                this.subAuthsmtpCancel.setShowing(false);
                
              
             
    	  
	  } catch(e) {
		  console.error('ERROR IN Dilog_subscription_authSMTP_CancelButton1Click: ' + e); 
	  } 
  },
//=========================================================================  
//for the bulk marketing--------------------------------------------------
  subBulkMarkBuyClick: function(inSender) {
	  try {
            var bulkMarketingProductPlanId=this.subBulkMarkProduct.getDataValue();//productPlanId
            //alert(bulkMarketingProductPlanId);
            var count=this.ProdcutPlansTB.getCount(); 
            for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     //alert(record.planId);
                     if(record.planId==bulkMarketingProductPlanId){//Transaction_PlanId=Product_planID
                            //for read only ----
                            var readOnlyData=this.subBulkMarkProduct.readonly;
                                //alert(readOnlyData);
                            if(readOnlyData==true){//read only true
                                    if(record.price < this.subAccFundBalance.getDataValue()){//enough balance
                                            
                                            //for default value
                                            var count=this.ProdcutPlansTB.getCount(); 
                                            for(var j=0 ; j<count ; j++){
                                                 var record=this.ProdcutPlansTB.getData()[j];
                                                 //alert(record.planId);
                                                 if(record.planId==this.subBulkMarkProduct.getDataValue()){
                                                    var productPricetemp=record.price;
                                                     var productCr=record.credits;
                                                     var productAmount=record.amount;
                                                    //alert(productAmount);
                                                    this.bulkMarketintPrice.setDataValue(productPricetemp);
                                                    this.bulkMarketintCredits.setDataValue(productCr);
                                                    this.bulkMarAmt.setDataValue(productAmount);
                                                    if(this.subBulkMarkProduct.getDataValue()>= 17 && this.subBulkMarkProduct.getDataValue() <= 21){
                                                        var BTrue=true;
                                                        this.bulkMarketintRewnew.setDataValue(BTrue);
                                                    }
                                                    else{
                                                        var BTrue=false;
                                                        this.bulkMarketintRewnew.setDataValue(BTrue);
                                                    }
                                                    this.bulkMarkDate.setDataValue(new Date().getTime());
                                                    if(record.subscription){
                                                          var currentdt=new Date();
                                                           var yy=currentdt.getFullYear();
                                                           var year=yy+1;
                                                           var dt=currentdt.getDate();
                                                           var month=new Array(12);
                                                                month[0]="Jan";
                                                                month[1]="Feb";
                                                                month[2]="Mar";
                                                                month[3]="Apr";
                                                                month[4]="May";
                                                                month[5]="Jun";
                                                                month[6]="Jul";
                                                                month[7]="Aug";
                                                                month[8]="Sep";
                                                                month[9]="Oct";
                                                                month[10]="Nov";
                                                                month[11]="Dec";
                                                                //alert(currentdt.getMonth()+1);
                                                               var mmm=month[currentdt.getMonth()];
                                                               var dateString=dt+"/"+mmm+"/"+year;
                                                               var exDate=new Date(dateString);
                                                               this.bulkMarkExpire.setDataValue(exDate);
                                                     }else{
                                                              var currentdt=new Date();
                                                               var yy=currentdt.getFullYear();
                                                               var dt=currentdt.getDate();
                                                               var month=new Array(12);
                                                                    month[0]="Jan";
                                                                    month[1]="Feb";
                                                                    month[2]="Mar";
                                                                    month[3]="Apr";
                                                                    month[4]="May";
                                                                    month[5]="Jun";
                                                                    month[6]="Jul";
                                                                    month[7]="Aug";
                                                                    month[8]="Sep";
                                                                    month[9]="Oct";
                                                                    month[10]="Nov";
                                                                    month[11]="Dec";
                                                                    
                                                                   var mmm=month[currentdt.getMonth()+1];
                                                                   var dateString=dt+"/"+mmm+"/"+yy;
                                                                   var exDate=new Date(dateString);
                                                                   this.bulkMarkExpire.setDataValue(exDate);
                                                    }
                                                 }
                                            }
                                
                                            //dialog box for read only
                                            this.Dialog_subReadOnlyBye_BulkMark.setUserPrompt(this.subBulkMarkProduct.getDisplayValue()+" you wish to purchase");
                                            this.Dialog_subReadOnlyBye_BulkMark.show();
                                    }
                                    else{//not enought balance
                                        this.subscriNotEnoughtbal.show();
                                    }
                            }
                            else if(record.price < this.subAccFundBalance.getDataValue()){//for enought balance---[product_plans.price] < [accounts.balance] 
                                  var productName=this.subBulkMarkProduct.getDisplayValue();
                                  this.subscriBulkMarketingbal1.setUserPrompt("Are you sure you want to Buy/Subscribe to the Product "+productName+"<br>This cannot be reversed if you click 'Yes Please'");
                                  this.subscriBulkMarketingbal1.show();
                            }
                            else{//not enought balance
                              this.subscriNotEnoughtbal.show();
                           }
                     }
                 }
		  
	  } catch(e) {
		  console.error('ERROR IN subBulkMarkBuyClick: ' + e); 
	  } 
  },
  subBulkMarkProductChange: function(inSender) {//for the price,credit and renew field set which are hidden
      try {
                var count=this.ProdcutPlansTB.getCount(); 
                for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     //alert(record.planId);
                     if(record.planId==this.subBulkMarkProduct.getDataValue()){
                         var productPricetemp=record.price;
                         var productCr=record.credits;
                         var productAmount=record.amount;
                        //alert(productAmount);
                        this.bulkMarketintPrice.setDataValue(productPricetemp);
            	        this.bulkMarketintCredits.setDataValue(productCr);
                        this.bulkMarAmt.setDataValue(productAmount);
                        if(this.subBulkMarkProduct.getDataValue()>= 17 && this.subBulkMarkProduct.getDataValue() <= 21){
                            var BTrue=true;
                            this.bulkMarketintRewnew.setDataValue(BTrue);
                        }
                        else{
                            var BTrue=false;
                            this.bulkMarketintRewnew.setDataValue(BTrue);
                        }
                        this.bulkMarkDate.setDataValue(new Date().getTime());
                        if(record.subscription){
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var year=yy+1;
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        //alert(currentdt.getMonth()+1);
                                       var mmm=month[currentdt.getMonth()];
                                       var dateString=dt+"/"+mmm+"/"+year;
                                       var exDate=new Date(dateString);
                                       this.bulkMarkExpire.setDataValue(exDate);
                              }else{
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        
                                       var mmm=month[currentdt.getMonth()+1];
                                       var dateString=dt+"/"+mmm+"/"+yy;
                                       var exDate=new Date(dateString);
                                       this.bulkMarkExpire.setDataValue(exDate);
                              }
                     }
                }
                
	  } catch(e) {
		  console.error('ERROR IN subBulkMarkProductChange: ' + e); 
	  } 
  },
  subscriBulkMarketingbal1Button1Click: function(inSender, inButton, inText) {//for form insertion
      try {
           
              this.liveFrmBulkMarketing.operation="insert";
              this.liveFrmBulkMarketing.insertData();
              
           
	  } catch(e) {
		  console.error('ERROR IN subscriBulkMarketingbal1Button1Click: ' + e); 
	  } 
  },
  Dialog_subReadOnlyBye_BulkMarkButton1Click: function(inSender, inButton, inText) {
     try {
         
            this.liveFrmBulkMarketing.operation="insert";
            this.liveFrmBulkMarketing.insertData();
              
            
      } catch(e) {
		  console.error('ERROR IN subscriBulkMarketingbal1Button1Click: ' + e); 
	  } 
  },
  liveFrmBulkMarketingSuccess: function(inSender, inData) {
	  try {
                var diff=0;	 
                //diff=this.AccountInfoService.getData()[0].balance-this.bulkMarketintPrice.getDataValue();
                //this.subAccFundBalance.setDataValue(diff);
                
                var count=this.AccountInfoService.getCount();
                 for(var i=0;i<count;i++){
                     diff=this.AccountInfoService.getData()[i].balance-this.bulkMarketintPrice.getDataValue();
                     this.subAccFundBalance.setDataValue(diff); 
                }
                
                //updat the account table by query
                this.accounts_balance_authSMPT.input.setValue("bal", diff);
                this.accounts_balance_authSMPT.input.setValue("userId", this.bulkMarUserId.getDataValue());
                this.accounts_balance_authSMPT.update();
                        
                //update subscription table for maximailsCredits and maximailsActive
                var bulkMarketingProductPlanId=this.subBulkMarkProduct.getDataValue();
                //alert("for update productId"+bulkMarketingProductPlanId);
                var count=this.ProdcutPlansTB.getCount(); 
                for(var j=0 ; j<count ; j++){
                    var record=this.ProdcutPlansTB.getData()[j];
                    if(record.planId==bulkMarketingProductPlanId){
                         var productPlanCredit=0;
                         productPlanCredit=record.credits;
                         var countt=this.SubscriptionsTB.getCount();
                         //alert("subscription count"+count);
                         for(var k=0;k<countt;k++){
                             var record_subscription=this.SubscriptionsTB.getData()[k];
                             if(record_subscription.userId==this.bulkMarUserId.getDataValue()){
                                
                                
                                 
                                 var bulkMCredit=record_subscription.maximailsCredits;
                                 //alert("p_credit="+productPlanCredit);
                                 //alert("s_credit="+bulkMCredit);
                                 
                                 var totoal=0;
                                  total=parseInt(bulkMCredit) + parseInt(productPlanCredit) ;
                                 //alert("total="+total);
                                 
                                 this.subscriptions_bulkMarketing_maximailCredit.input.setValue("maximailsActive",true);
                                 this.subscriptions_bulkMarketing_maximailCredit.input.setValue("userId",this.bulkMarUserId.getDataValue());
                                 this.subscriptions_bulkMarketing_maximailCredit.input.setValue("maximailsCredits",total);
                                 this.subscriptions_bulkMarketing_maximailCredit.update();
                                 
                             }
                         }
                     }
                }
                
                 
                //diff tab for showing
                this.layerBulkMarketing.setShowing(true);
                this.bulkMarkHelp.setShowing(false);
                
                
               //refresh layer
               this.AccountInfoService.update();
               this.SubscriptionsTB.update();
               this.TransactionsTB.update();
               this.ProdcutPlansTB.update();
               this.subscriptionTabGrid.update();
               
           
	  } catch(e) {
		  console.error('ERROR IN liveFrmBulkMarketingSuccess: ' + e); 
	  } 
  },
  
  //------bulkMarketing CANCEL----------------------------------------------------------
  subBulkMarkCancelClick: function(inSender) {
      try {
                var count=this.TransactionsTB.getCount();
                for(var i=0 ; i<count ; i++){
                    var record=this.TransactionsTB.getData()[i];
                    
                    if(record.planId==this.subBulkMarkProduct.getDataValue()){
                        //alert(this.subBulkMarkProduct.getDataValue());
                        var productName=this.subBulkMarkProduct.getDisplayValue();
                        this.Dilog_subscription_bulikmarketing_Cancel.setUserPrompt("The subscription for "+productName+" will not be renewed on the expiry date");
                        this.Dilog_subscription_bulikmarketing_Cancel.show();
                    }
                }		  
		  
	  } catch(e) {
		  console.error('ERROR IN subBulkMarkCancelClick: ' + e); 
	  } 
  },
  
  
  
   Dilog_subscription_bulikmarketing_CancelButton1Click: function(inSender, inButton, inText) {
      try {
                this.subscriptions_transaction_Cancel_renew.input.setValue("renew",false);
                this.subscriptions_transaction_Cancel_renew.input.setValue("userId",this.bulkMarUserId.getDataValue());
                this.subscriptions_transaction_Cancel_renew.input.setValue("planId",this.subBulkMarkProduct.getDataValue());
                
                this.subBulkMarkCancel.setShowing(false);		  
		  
	  } catch(e) {
		  console.error('ERROR IN Dilog_subscription_bulikmarketing_CancelButton1Click: ' + e); 
	  } 
  },
  //for the spam score------------------------------------------------
  
  
  
  subSpamScorBuyClick: function(inSender) {
	  try {
            
            
            var spamScoreProductPlanId=this.subSpamScorProduct.getDataValue();//productPlanId
            
            var count=this.ProdcutPlansTB.getCount(); 
            for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     //alert(record.planId);
                     if(record.planId==spamScoreProductPlanId){
                            //for read only ----Dialog_subReadOnlyBye_spamCore
                            var readOnlyData=this.subSpamScorProduct.readonly;
                            if(readOnlyData==true){//for read only
                                    if(record.price < this.subAccFundBalance.getDataValue()){
                                        
                                        var count=this.ProdcutPlansTB.getCount(); 
                                        for(var j=0 ; j<count ; j++){
                                                 var record=this.ProdcutPlansTB.getData()[j];
                                                 //alert(record.planId);
                                                 if(record.planId==this.subSpamScorProduct.getDataValue()){
                                                       //defalut value
                                                           var productPrice=record.price;
                                                          var productCr=record.credits;
                                                          var productAmt=record.amount;
                                                          //alert(productAmt);
                                                          this.spamScorePrice.setDataValue(productPrice);
                                                          this.spamScoreCredit.setDataValue(productCr);
                                                          this.spamScoreAmt.setDataValue(productAmt);
                                                          if(this.subSpamScorProduct.getDataValue()>= 34 && this.subSpamScorProduct.getDataValue() <= 36){//for renew
                                                             var BTrue=true;
                                                            this.spamScoreRenew.setDataValue(BTrue);
                                                          }
                                                          else{
                                                             var BTrue=false;
                                                            this.spamScoreRenew.setDataValue(BTrue);
                                                         }
                                                         this.spamScoreDate.setDataValue(new Date().getTime());
                                                         if(record.subscription){
                                                              var currentdt=new Date();
                                                               var yy=currentdt.getFullYear();
                                                               var year=yy+1;
                                                               var dt=currentdt.getDate();
                                                               var month=new Array(12);
                                                                    month[0]="Jan";
                                                                    month[1]="Feb";
                                                                    month[2]="Mar";
                                                                    month[3]="Apr";
                                                                    month[4]="May";
                                                                    month[5]="Jun";
                                                                    month[6]="Jul";
                                                                    month[7]="Aug";
                                                                    month[8]="Sep";
                                                                    month[9]="Oct";
                                                                    month[10]="Nov";
                                                                    month[11]="Dec";
                                                                    //alert(currentdt.getMonth()+1);
                                                                   var mmm=month[currentdt.getMonth()];
                                                                   var dateString=dt+"/"+mmm+"/"+year;
                                                                   var exDate=new Date(dateString);
                                                                   this.spamScoreExpire.setDataValue(exDate);
                                                          }else{
                                                              var currentdt=new Date();
                                                               var yy=currentdt.getFullYear();
                                                               var dt=currentdt.getDate();
                                                               var month=new Array(12);
                                                                    month[0]="Jan";
                                                                    month[1]="Feb";
                                                                    month[2]="Mar";
                                                                    month[3]="Apr";
                                                                    month[4]="May";
                                                                    month[5]="Jun";
                                                                    month[6]="Jul";
                                                                    month[7]="Aug";
                                                                    month[8]="Sep";
                                                                    month[9]="Oct";
                                                                    month[10]="Nov";
                                                                    month[11]="Dec";
                                                                    
                                                                   var mmm=month[currentdt.getMonth()+1];
                                                                   var dateString=dt+"/"+mmm+"/"+yy;
                                                                   var exDate=new Date(dateString);
                                                                   this.spamScoreExpire.setDataValue(exDate);
                                                          }
                                                 }
                                        }
                                        //for read only dialog box
                                        this.Dialog_subReadOnlyBye_spamCore.setUserPrompt(this.subSpamScorProduct.getDisplayValue()+" you wish to purchase");
                                        this.Dialog_subReadOnlyBye_spamCore.show();
                                    }
                                    else{
                                        this.subscriNotEnoughtbal.show();
                                    }
                            }
                            else if(record.price < this.subAccFundBalance.getDataValue()){//for not enought balance---[product_plans.price] < [accounts.balance] 
                                  var productName=this.subSpamScorProduct.getDisplayValue();
                                  this.subscriSpamSscore1.setUserPrompt("Are you sure you want to Buy/Subscribe to the Product "+productName+"<br>This cannot be reversed if you click 'Yes Please'");
                                  this.subscriSpamSscore1.show();
                                  
                            }
                            else{
                               this.subscriNotEnoughtbal.show();
                            }
                     }
            }
		  
	  } catch(e) {
		  console.error('ERROR IN subSpamScorBuyClick: ' + e); 
	  } 
  },
  subSpamScorProductChange: function(inSender) {
	  try {
		   var count=this.ProdcutPlansTB.getCount(); 
            for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     //alert(record.planId);
                     if(record.planId==this.subSpamScorProduct.getDataValue()){
                           //defalut value
                              var productPrice=record.price;
                              var productCr=record.credits;
                              var productAmt=record.amount;
                              //alert(productAmt);
                              this.spamScorePrice.setDataValue(productPrice);
                              this.spamScoreCredit.setDataValue(productCr);
                              this.spamScoreAmt.setDataValue(productAmt);
                              if(this.subSpamScorProduct.getDataValue()>= 34 && this.subSpamScorProduct.getDataValue() <= 36){//for renew
                                 var BTrue=true;
                                this.spamScoreRenew.setDataValue(BTrue);
                              }
                              else{
                                 var BTrue=false;
                                this.spamScoreRenew.setDataValue(BTrue);
                             }
                             this.spamScoreDate.setDataValue(new Date().getTime());
                             if(record.subscription){
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var year=yy+1;
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        //alert(currentdt.getMonth()+1);
                                       var mmm=month[currentdt.getMonth()];
                                       var dateString=dt+"/"+mmm+"/"+year;
                                       var exDate=new Date(dateString);
                                       this.spamScoreExpire.setDataValue(exDate);
                              }else{
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        
                                       var mmm=month[currentdt.getMonth()+1];
                                       var dateString=dt+"/"+mmm+"/"+yy;
                                       var exDate=new Date(dateString);
                                       this.spamScoreExpire.setDataValue(exDate);
                              }
                     }
            }
		  
	  } catch(e) {
		  console.error('ERROR IN subSpamScorProductChange: ' + e); 
	  } 
  },
  subscriSpamSscore1Button1Click: function(inSender, inButton, inText) {
	  try {
              this.liveFrmSpamScore.operation="insert";
              this.liveFrmSpamScore.insertData();	
              
        } catch(e) {
		  console.error('ERROR IN subscriSpamSscore1Button1Click: ' + e); 
	  } 
  },
  Dialog_subReadOnlyBye_spamCoreButton1Click: function(inSender, inButton, inText) {
      try {
              this.liveFrmSpamScore.operation="insert";
              this.liveFrmSpamScore.insertData();    
              
       }catch(e) {
		  console.error('ERROR IN Dialog_subReadOnlyBye_spamCoreButton1Click: ' + e); 
	  } 
  },
  liveFrmSpamScoreSuccess: function(inSender, inData) {
	  try {
             var diff=0;
             //diff=this.AccountInfoService.getData()[0].balance-this.spamScorePrice.getDataValue();
             //this.subAccFundBalance.setDataValue(diff);   
             
             var count=this.AccountInfoService.getCount();
             for(var i=0;i<count;i++){
                 diff=this.AccountInfoService.getData()[i].balance-this.spamScorePrice.getDataValue();
                 this.subAccFundBalance.setDataValue(diff); 
            }
             
             //updat the account table by query
             this.accounts_balance_authSMPT.input.setValue("bal", diff);
             this.accounts_balance_authSMPT.input.setValue("userId", this.spamScoreUserid.getDataValue());
             this.accounts_balance_authSMPT.update();
             
             //update subscription table for spam_score_Activite and spam_score_credit
             
             var spamScoreProductPlanId=this.subSpamScorProduct.getDataValue();
             var count=this.ProdcutPlansTB.getCount(); 
                for(var j=0 ; j<count ; j++){
                    var record=this.ProdcutPlansTB.getData()[j];
                    if(record.planId==spamScoreProductPlanId){
                        var productPlanCredit=0;
                        productPlanCredit=record.credits;
                        
                        var countt=this.SubscriptionsTB.getCount();
                        //alert("subscription count"+count);
                         for(var k=0;k<countt;k++){
                             var record_subscription=this.SubscriptionsTB.getData()[k];
                             if(record_subscription.userId==this.spamScoreUserid.getDataValue()){
                                 var spamCredit=0;
                                 spamCredit=record_subscription.spamscoreCredits;
                                 //alert("p_credit="+productPlanCredit);
                                 //alert("s_credit="+spamCredit);
                                 
                                 
                                 var total = 0;
                                 total= parseInt(spamCredit) + parseInt(productPlanCredit);
                                 //alert("total="+total);
                                 this.subscriptions_spamScore_spamscoreCredits.input.setValue("spamscoreActive",true);
                                 this.subscriptions_spamScore_spamscoreCredits.input.setValue("userId",this.spamScoreUserid.getDataValue());
                                 this.subscriptions_spamScore_spamscoreCredits.input.setValue("spamscoreCredits",total);
                                 this.subscriptions_spamScore_spamscoreCredits.update();
                             }
                         }
                    }
                }
             
             //diff panel showing [on] [off]
             this.panel2.setShowing(true);
             this.spamScorHelp.setShowing(false);
             
              //refresh layer
               this.AccountInfoService.update();
               this.SubscriptionsTB.update();
               this.TransactionsTB.update();
               this.ProdcutPlansTB.update();
               this.subscriptionTabGrid.update();
		  
	  } catch(e) {
		  console.error('ERROR IN liveFrmSpamScoreSuccess: ' + e); 
	  } 
  },
  
  //for spamScore CANCEL--------------------------------------------
  subSpamScorCancelClick: function(inSender) {
      try {
                var count=this.TransactionsTB.getCount();
                for(var i=0 ; i<count ; i++){
                    var record=this.TransactionsTB.getData()[i];
                    
                    if(record.planId==this.subSpamScorProduct.getDataValue()){
                       // alert(this.subSpamScorProduct.getDataValue());
                        var productName=this.subSpamScorProduct.getDisplayValue();
                        this.Dilog_subscription_spamScore_Cancel.setUserPrompt("The subscription for "+productName+" will not be renewed on the expiry date");
                        this.Dilog_subscription_spamScore_Cancel.show();
                    }
                }		  
		  
	  } catch(e) {
		  console.error('ERROR IN subSpamScorCancelClick: ' + e); 
	  } 
  },
  Dilog_subscription_spamScore_CancelButton1Click: function(inSender, inButton, inText) {
	  try {
		        this.subscriptions_transaction_Cancel_renew.input.setValue("renew",false);
                this.subscriptions_transaction_Cancel_renew.input.setValue("userId",this.spamScoreUserid.getDataValue());
                this.subscriptions_transaction_Cancel_renew.input.setValue("planId",this.subSpamScorProduct.getDataValue());
                
                this.subSpamScorCancel.setShowing(false);
		  
	  } catch(e) {
		  console.error('ERROR IN Dilog_subscription_spamScore_CancelButton1Click: ' + e); 
	  } 
  },
 
  
  //for email editor----------------------------------------------
  
  subEmailEdBuyClick: function(inSender) {
	  try {
           
            
            var EmailEdProductPlanId=this.subEmailEdProduct.getDataValue();//productPlanId
            var count=this.ProdcutPlansTB.getCount(); 
            for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     //alert(record.planId);
                     if(record.planId==EmailEdProductPlanId){
                         
                        //for read only ----
                        var readOnlyData=this.subEmailEdProduct.readonly;
                        if(readOnlyData==true){//for read only 
                                 if(record.price < this.subAccFundBalance.getDataValue()){
                                             //defalut value for read only product
                                             var count=this.ProdcutPlansTB.getCount(); 
                                            for(var j=0 ; j<count ; j++){
                                                     var record=this.ProdcutPlansTB.getData()[j];
                                                     //alert(record.planId);
                                                     if(record.planId==this.subEmailEdProduct.getDataValue()){
                                                          var productPrice=record.price;
                                                         var productCr=record.credits;
                                                         var productAmountt=record.amount;
                                                         //alert(productAmountt);
                                                         this.EmailEdPrice.setDataValue(productPrice);
                                                         this.EmailEdCredit.setDataValue(productCr);
                                                         this.EmailEdAmount.setDataValue(productAmountt);
                                                         var BTrue=true;
                                                         this.EmailEdRenew.setDataValue(BTrue);
                                                         this.EmailEdDate.setDataValue(new Date().getTime());
                                                          if(record.subscription){
                                                                  var currentdt=new Date();
                                                                   var yy=currentdt.getFullYear();
                                                                   var year=yy+1;
                                                                   var dt=currentdt.getDate();
                                                                   var month=new Array(12);
                                                                        month[0]="Jan";
                                                                        month[1]="Feb";
                                                                        month[2]="Mar";
                                                                        month[3]="Apr";
                                                                        month[4]="May";
                                                                        month[5]="Jun";
                                                                        month[6]="Jul";
                                                                        month[7]="Aug";
                                                                        month[8]="Sep";
                                                                        month[9]="Oct";
                                                                        month[10]="Nov";
                                                                        month[11]="Dec";
                                                                        //alert(currentdt.getMonth()+1);
                                                                       var mmm=month[currentdt.getMonth()];
                                                                       var dateString=dt+"/"+mmm+"/"+year;
                                                                       var exDate=new Date(dateString);
                                                                       this.EmailEdExpire.setDataValue(exDate);
                                                            }else{
                                                                  var currentdt=new Date();
                                                                   var yy=currentdt.getFullYear();
                                                                   var dt=currentdt.getDate();
                                                                   var month=new Array(12);
                                                                        month[0]="Jan";
                                                                        month[1]="Feb";
                                                                        month[2]="Mar";
                                                                        month[3]="Apr";
                                                                        month[4]="May";
                                                                        month[5]="Jun";
                                                                        month[6]="Jul";
                                                                        month[7]="Aug";
                                                                        month[8]="Sep";
                                                                        month[9]="Oct";
                                                                        month[10]="Nov";
                                                                        month[11]="Dec";
                                                                        
                                                                       var mmm=month[currentdt.getMonth()+1];
                                                                       var dateString=dt+"/"+mmm+"/"+yy;
                                                                       var exDate=new Date(dateString);
                                                                       this.EmailEdExpire.setDataValue(exDate);
                                                             }
                                                     }
                                            }
                                             //for read only dialig box
                                             this.Dialog_subReadOnlyBye_EmailEd.setUserPrompt(this.subEmailEdProduct.getDataValue()+" you wish to purchase");
                                             this.Dialog_subReadOnlyBye_EmailEd.show();
                                 }
                                 else{
                                         this.subscriNotEnoughtbal.show();
                                 }
                        }
                        else if(record.price < this.subAccFundBalance.getDataValue()){//for not enought balance---[product_plans.price] < [accounts.balance] 
                            var productName=this.subEmailEdProduct.getDisplayValue();
                            this.subscriEmailEditor1.setUserPrompt("Are you sure you want to Buy/Subscribe to the Product "+productName+"<br>This cannot be reversed if you click 'Yes Please'");
                            this.subscriEmailEditor1.show();
                         }
                         else{
                             this.subscriNotEnoughtbal.show();
                         }
                     }
            }
            
		  
	  } catch(e) {
		  console.error('ERROR IN subEmailEdBuyClick: ' + e); 
	  } 
  },
  subEmailEdProductChange: function(inSender) {
	  try {
            var count=this.ProdcutPlansTB.getCount(); 
            for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     //alert(record.planId);
                     if(record.planId==this.subEmailEdProduct.getDataValue()){
                         var productPrice=record.price;
                         var productCr=record.credits;
                         var productAmountt=record.amount;
                         //alert(productAmountt);
                         this.EmailEdPrice.setDataValue(productPrice);
                         this.EmailEdCredit.setDataValue(productCr);
                         this.EmailEdAmount.setDataValue(productAmountt);
                         var BTrue=true;
                         this.EmailEdRenew.setDataValue(BTrue);
                         this.EmailEdDate.setDataValue(new Date().getTime());
                         if(record.subscription){
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var year=yy+1;
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        //alert(currentdt.getMonth()+1);
                                       var mmm=month[currentdt.getMonth()];
                                       var dateString=dt+"/"+mmm+"/"+year;
                                       var exDate=new Date(dateString);
                                       this.EmailEdExpire.setDataValue(exDate);
                              }else{
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        
                                       var mmm=month[currentdt.getMonth()+1];
                                       var dateString=dt+"/"+mmm+"/"+yy;
                                       var exDate=new Date(dateString);
                                       this.EmailEdExpire.setDataValue(exDate);
                              }
                         
                     }
            }
		  
	  } catch(e) {
		  console.error('ERROR IN subEmailEdProductChange: ' + e); 
	  } 
  },
  subscriEmailEditor1Button1Click: function(inSender, inButton, inText) {
	  try {
             this.liveFrmEmailEditor.operation="insert";
             this.liveFrmEmailEditor.insertData();    	 
            
     } catch(e) {
		  console.error('ERROR IN subscriEmailEditor1Button1Click: ' + e); 
	  } 
  },
  
  Dialog_subReadOnlyBye_EmailEdButton1Click: function(inSender, inButton, inText) {
      try {
		  this.liveFrmEmailEditor.operation="insert";
          this.liveFrmEmailEditor.insertData();
          
       } catch(e) {
		  console.error('ERROR IN Dialog_subReadOnlyBye_EmailEdButton1Click: ' + e); 
	  } 
  },
  liveFrmEmailEditorSuccess: function(inSender, inData) {
	  try {
            var diff=0;
             //var diff=this.AccountInfoService.getData()[0].balance-this.EmailEdPrice.getDataValue();
             //this.subAccFundBalance.setDataValue(diff);		  
             
             var count=this.AccountInfoService.getCount();
             for(var i=0;i<count;i++){
                 diff=this.AccountInfoService.getData()[i].balance-this.EmailEdPrice.getDataValue();
                 this.subAccFundBalance.setDataValue(diff); 
            }
             
              //updat the account table by query
             this.accounts_balance_authSMPT.input.setValue("bal", diff);
             this.accounts_balance_authSMPT.input.setValue("userId", this.EmailEdUserId.getDataValue());
             this.accounts_balance_authSMPT.update();
             
             //update subscription table for emaileditor_Activite and email_credit
             var emaileditorProductPlanId=this.subEmailEdProduct.getDataValue();
             var count=this.ProdcutPlansTB.getCount(); 
                for(var j=0 ; j<count ; j++){
                    var record=this.ProdcutPlansTB.getData()[j];
                    if(record.planId==emaileditorProductPlanId){
                        var productPlanCredit=0;
                        productPlanCredit=record.credits;
                        
                        var countt=this.SubscriptionsTB.getCount();
                        for(var k=0;k<countt;k++){
                             var record_subscription=this.SubscriptionsTB.getData()[k];
                             if(record_subscription.userId==this.EmailEdUserId.getDataValue()){
                                 var EmailEdCredit=0;
                                 EmailEdCredit=record_subscription.emaileditorCredits;
                                 //alert("p_credit="+productPlanCredit);
                                 //alert("s_credit="+EmailEdCredit);
                                 
                                 var total=0;
                                 total=parseInt(EmailEdCredit) + parseInt(productPlanCredit);
                                 //alert("total="+total);
                                 
                                 this.subscriptions_emailEditor_emailCredits.input.setValue("emaileditorActive",true);
                                 this.subscriptions_emailEditor_emailCredits.input.setValue("userId",this.EmailEdUserId.getDataValue());
                                 this.subscriptions_emailEditor_emailCredits.input.setValue("emaileditorCredits",total);
                                 this.subscriptions_emailEditor_emailCredits.update();
                             }
                        }
                    }
                }
             
             //other panel showing hide setting
             this.panel3.setShowing(true);
             this.emailEdHelp.setShowing(false);
             //refresh layer
               this.AccountInfoService.update();
               this.SubscriptionsTB.update();
               this.TransactionsTB.update();
               this.ProdcutPlansTB.update();
               this.subscriptionTabGrid.update();
      
      } catch(e) {
		  console.error('ERROR IN liveFrmEmailEditorSuccess: ' + e); 
	  } 
  },
  //for email editor CANCEL-------------------------
  
   subEmailEdCancelClick: function(inSender) {
      try {
                        
                 var count=this.TransactionsTB.getCount();
                for(var i=0 ; i<count ; i++){
                    var record=this.TransactionsTB.getData()[i];
                    
                    if(record.planId==this.subEmailEdProduct.getDataValue()){
                        //alert(this.subEmailEdProduct.getDataValue());
                        var productName=this.subEmailEdProduct.getDisplayValue();
                        this.Dilog_subscription_EmailEditor_cancel.setUserPrompt("The subscription for "+productName+" will not be renewed on the expiry date");
                        this.Dilog_subscription_EmailEditor_cancel.show();
                    }
                }
		  
	  } catch(e) {
		  console.error('ERROR IN subEmailEdCancelClick: ' + e); 
	  } 
  },
  Dilog_subscription_EmailEditor_cancelButton1Click: function(inSender, inButton, inText) {
	  try {
                this.subscriptions_transaction_Cancel_renew.input.setValue("renew",false);
                this.subscriptions_transaction_Cancel_renew.input.setValue("userId",this.EmailEdUserId.getDataValue());
                this.subscriptions_transaction_Cancel_renew.input.setValue("planId",this.subEmailEdProduct.getDataValue());
                
                this.subEmailEdCancel.setShowing(false);		  
		  
	  } catch(e) {
		  console.error('ERROR IN Dilog_subscription_EmailEditor_cancelButton1Click: ' + e); 
	  } 
  },
  //------------------------------------------------------------------------------------------------------------------------------------
  //for email deliver ----------------------------
  subEmailDelBuyClick: function(inSender) {
	  try {
           	
            
            var EmailEdProductPlanId=this.subEmailDelProduct.getDataValue();
            var count=this.ProdcutPlansTB.getCount(); 
            for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     if(record.planId==EmailEdProductPlanId){
                                    //for read only ----Dialog_subReadOnlyBye_EmailDe
                                    var readOnlyData=this.subEmailDelProduct.readonly;
                                    if(readOnlyData==true){//for read only
                                            if(record.price < this.subAccFundBalance.getDataValue()){  
                                                
                                                    //for the defalut value for read only
                                                     var count=this.ProdcutPlansTB.getCount(); 
                                                     for(var j=0 ; j<count ; j++){
                                                             var record=this.ProdcutPlansTB.getData()[j];
                                                             if(record.planId==this.subEmailDelProduct.getDataValue()){
                                                                 var productPrice=record.price;
                                                                 var productCredit=record.credits;
                                                                 var productAmnt=record.amount;
                                                                 //alert(productAmnt);
                                                                 this.emailDelPrice.setDataValue(productPrice);
                                                                 this.emailDelCredit.setDataValue(productCredit);
                                                                 this.emaiDelAmount.setDataValue(productAmnt);
                                                                 if(this.subEmailDelProduct.getDataValue()>= 22 && this.subEmailDelProduct.getDataValue() <= 28){//for renew
                                                                         var BTrue=true;
                                                                        this.emaiDelRenew.setDataValue(BTrue);
                                                                 }
                                                                 else{
                                                                         var BTrue=false;
                                                                        this.emaiDelRenew.setDataValue(BTrue);
                                                                 }
                                                                 this.emaiDelDate.setDataValue(new Date().getTime());
                                                                 if(record.subscription){
                                                                      var currentdt=new Date();
                                                                       var yy=currentdt.getFullYear();
                                                                       var year=yy+1;
                                                                       var dt=currentdt.getDate();
                                                                       var month=new Array(12);
                                                                            month[0]="Jan";
                                                                            month[1]="Feb";
                                                                            month[2]="Mar";
                                                                            month[3]="Apr";
                                                                            month[4]="May";
                                                                            month[5]="Jun";
                                                                            month[6]="Jul";
                                                                            month[7]="Aug";
                                                                            month[8]="Sep";
                                                                            month[9]="Oct";
                                                                            month[10]="Nov";
                                                                            month[11]="Dec";
                                                                            //alert(currentdt.getMonth()+1);
                                                                           var mmm=month[currentdt.getMonth()];
                                                                           var dateString=dt+"/"+mmm+"/"+year;
                                                                           var exDate=new Date(dateString);
                                                                           this.emaiDelExpire.setDataValue(exDate);
                                                                  }else{
                                                                          var currentdt=new Date();
                                                                           var yy=currentdt.getFullYear();
                                                                           var dt=currentdt.getDate();
                                                                           var month=new Array(12);
                                                                                month[0]="Jan";
                                                                                month[1]="Feb";
                                                                                month[2]="Mar";
                                                                                month[3]="Apr";
                                                                                month[4]="May";
                                                                                month[5]="Jun";
                                                                                month[6]="Jul";
                                                                                month[7]="Aug";
                                                                                month[8]="Sep";
                                                                                month[9]="Oct";
                                                                                month[10]="Nov";
                                                                                month[11]="Dec";
                                                                                
                                                                               var mmm=month[currentdt.getMonth()+1];
                                                                               var dateString=dt+"/"+mmm+"/"+yy;
                                                                               var exDate=new Date(dateString);
                                                                               this.emaiDelExpire.setDataValue(exDate);
                                                                  }
                                                             }
                                                     }
                                                    //for defalut value set
                                                    this.Dialog_subReadOnlyBye_EmailDe.setUserPrompt(this.subEmailDelProduct.getDisplayValue()+" you wish to purchase");
                                                    this.Dialog_subReadOnlyBye_EmailDe.show();
                                             }
                                             else{
                                                    this.subscriNotEnoughtbal.show();
                                            }
                                    } 
                                    else if(record.price < this.subAccFundBalance.getDataValue()){
                                         var productName=this.subEmailDelProduct.getDisplayValue();
                                         this.subscriEmailDeliver1.setUserPrompt("Are you sure you want to Buy/Subscribe to the Product "+productName+"<br>This cannot be reversed if you click 'Yes Please'");
                                         this.subscriEmailDeliver1.show();
                                    }
                                    else{
                                         this.subscriNotEnoughtbal.show();
                                    }
                     }
            }
		  
	  } catch(e) {
		  console.error('ERROR IN subEmailDelBuyClick: ' + e); 
	  } 
  },
  subEmailDelProductChange: function(inSender) {
	  try {
             var count=this.ProdcutPlansTB.getCount(); 
             for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     if(record.planId==this.subEmailDelProduct.getDataValue()){
                         var productPrice=record.price;
                         var productCredit=record.credits;
                         var productAmnt=record.amount;
                         //alert(productAmnt);
                         this.emailDelPrice.setDataValue(productPrice);
                         this.emailDelCredit.setDataValue(productCredit);
                         this.emaiDelAmount.setDataValue(productAmnt);
                         if(this.subEmailDelProduct.getDataValue()>= 22 && this.subEmailDelProduct.getDataValue() <= 28){//for renew
                                 var BTrue=true;
                                this.emaiDelRenew.setDataValue(BTrue);
                         }
                         else{
                                 var BTrue=false;
                                this.emaiDelRenew.setDataValue(BTrue);
                         }
                         this.emaiDelDate.setDataValue(new Date().getTime());
                         if(record.subscription){
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var year=yy+1;
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        //alert(currentdt.getMonth()+1);
                                       var mmm=month[currentdt.getMonth()];
                                       var dateString=dt+"/"+mmm+"/"+year;
                                       var exDate=new Date(dateString);
                                       this.emaiDelExpire.setDataValue(exDate);
                              }else{
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        
                                       var mmm=month[currentdt.getMonth()+1];
                                       var dateString=dt+"/"+mmm+"/"+yy;
                                       var exDate=new Date(dateString);
                                       this.emaiDelExpire.setDataValue(exDate);
                              }
                    }
             }
		  
	  } catch(e) {
		  console.error('ERROR IN subEmailDelProductChange: ' + e); 
	  } 
  },
  subscriEmailDeliver1Button1Click: function(inSender, inButton, inText) {
	  try {
              this.liveFrmEmailDelivery.operation="insert";
              this.liveFrmEmailDelivery.insertData();   
              
           } catch(e) {
		  console.error('ERROR IN subscriEmailDeliver1Button1Click: ' + e); 
	  } 
  },
  Dialog_subReadOnlyBye_EmailDeButton1Click: function(inSender, inButton, inText) {
      try {
		   this.liveFrmEmailDelivery.operation="insert";
           this.liveFrmEmailDelivery.insertData();
     } catch(e) {
		  console.error('ERROR IN Dialog_subReadOnlyBye_EmailDeButton1Click: ' + e); 
	  } 
  },
  liveFrmEmailDeliverySuccess: function(inSender, inData) {
	  try {
             var diff=0;
             //var diff=this.AccountInfoService.getData()[0].balance-this.emailDelPrice.getDataValue();
             //this.subAccFundBalance.setDataValue(diff);       
              var count=this.AccountInfoService.getCount();
             for(var i=0;i<count;i++){
                 diff=this.AccountInfoService.getData()[i].balance-this.emailDelPrice.getDataValue();
                 this.subAccFundBalance.setDataValue(diff); 
            }
             //updat the account table by query
             this.accounts_balance_authSMPT.input.setValue("bal", diff);
             this.accounts_balance_authSMPT.input.setValue("userId", this.emaiDelUserID.getDataValue());
             this.accounts_balance_authSMPT.update();
             
             
             //update subscription table for emailDeliveryCredits and emailDeliveryActive
             var emailDelProductPlanId=this.subEmailDelProduct.getDataValue();
              var count=this.ProdcutPlansTB.getCount(); 
              for(var j=0 ; j<count ; j++){
                   var record=0;
                   record=this.ProdcutPlansTB.getData()[j];
                   if(record.planId==emailDelProductPlanId){
                       var productPlanCredit=0;
                       productPlanCredit=record.credits;
                       var countt=this.SubscriptionsTB.getCount();
                       for(var k=0;k<countt;k++){
                             var record_subscription=this.SubscriptionsTB.getData()[k];
                             if(record_subscription.userId==this.emaiDelUserID.getDataValue()){
                                 var emailDeleveryCredit=0;
                                 emailDeleveryCredit=record_subscription.emaildeliveryCredits;
                                 //alert("p_credit="+productPlanCredit);
                                 //alert("s_credit="+emailDeleveryCredit);
                                 
                                 
                                 var total=0;
                                 total=parseInt(emailDeleveryCredit)+parseInt(productPlanCredit);
                                 //alert("total="+total);
                                 
                                 this.subscriptions_emailDelevery.input.setValue("emaildeliveryActive",true);
                                 this.subscriptions_emailDelevery.input.setValue("userId",this.emaiDelUserID.getDataValue());
                                 this.subscriptions_emailDelevery.input.setValue("emaildeliveryCredits",total);
                                 this.subscriptions_emailDelevery.update();
                             }
                       }
                   }
              }
             
             //diff panel showing [on] [off]
             this.panel4.setShowing(true);
             this.emailDelHelp.setShowing(false);
             
             //refresh layer
               this.AccountInfoService.update();
               this.SubscriptionsTB.update();
               this.TransactionsTB.update();
               this.ProdcutPlansTB.update();
               this.subscriptionTabGrid.update();
             
             
		  
	  } catch(e) {
		  console.error('ERROR IN liveFrmEmailDeliverySuccess: ' + e); 
	  } 
  },
 //for emaildeliveryCancel------
  subEmailDelCancelClick: function(inSender) {
      try {
                 var count=this.TransactionsTB.getCount();
                for(var i=0 ; i<count ; i++){
                    var record=this.TransactionsTB.getData()[i];
                    
                    if(record.planId==this.subEmailDelProduct.getDataValue()){
                        //alert(this.subEmailDelProduct.getDataValue());
                        var productName=this.subEmailDelProduct.getDisplayValue();
                        this.Dilog_subscription_EmailDelivery_Cancel.setUserPrompt("The subscription for "+productName+" will not be renewed on the expiry date");
                        this.Dilog_subscription_EmailDelivery_Cancel.show();
                    }
                }		  
		  
	  } catch(e) {
		  console.error('ERROR IN subEmailDelCancelClick: ' + e); 
	  } 
  },
  
   Dilog_subscription_EmailDelivery_CancelButton1Click: function(inSender, inButton, inText) {
      try {
		        this.subscriptions_transaction_Cancel_renew.input.setValue("renew",false);
                this.subscriptions_transaction_Cancel_renew.input.setValue("userId",this.emaiDelUserID.getDataValue());
                this.subscriptions_transaction_Cancel_renew.input.setValue("planId",this.subEmailDelProduct.getDataValue());
                this.subscriptions_transaction_Cancel_renew.update();
                
                this.subEmailDelCancel.setShowing(false);
		  
	  } catch(e) {
		  console.error('ERROR IN Dilog_subscription_EmailDelivery_CancelButton1Click: ' + e); 
	  } 
  },
 //for WEB-mail-------------------------------------------------------------
  subWebmailBuyClick: function(inSender) {
	  try {
           var webMailPlanId=this.subWebmailProduct.getDataValue();//productPlanId
            
             //select the product_planId=spamscoreWMV datavalue
            var count=this.ProdcutPlansTB.getCount(); 
            for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     if(record.planId==webMailPlanId){//product_plan[plan.id]=webmailAWM
                               //for read only ----Dilog_subscription_WebMail
                                var readOnlyData=this.subWebmailProduct.readonly;
                                if(readOnlyData==true){
                                        if(record.price < this.subAccFundBalance.getDataValue()){
                                            
                                            //defalut value for read only
                                            var count=this.ProdcutPlansTB.getCount(); 
                                            for(var j=0 ; j<count ; j++){
                                                     var record=this.ProdcutPlansTB.getData()[j];
                                                     //alert(record.planId);
                                                    if(record.planId==this.subWebmailProduct.getDataValue()){    
                                                        var productPrice=record.price;
                                                            var productCr=record.credits;
                                                            var prodAmount=record.amount;
                                                            //alert(prodAmount);
                                                            this.subWebMailAmount.setDataValue(subWebMailAmount);
                                                            this.subWebMailPrice.setDataValue(productPrice);
                                                            this.subWebMailCredit.setDataValue(productCr);
                                                         var BTrue=true;
                                                         this.subWebMailRenew.setDataValue(BTrue);
                                                         this.subWebMailDate.setDataValue(new Date().getTime());
                                                          if(record.subscription){
                                                              var currentdt=new Date();
                                                               var yy=currentdt.getFullYear();
                                                               var year=yy+1;
                                                               var dt=currentdt.getDate();
                                                               var month=new Array(12);
                                                                    month[0]="Jan";
                                                                    month[1]="Feb";
                                                                    month[2]="Mar";
                                                                    month[3]="Apr";
                                                                    month[4]="May";
                                                                    month[5]="Jun";
                                                                    month[6]="Jul";
                                                                    month[7]="Aug";
                                                                    month[8]="Sep";
                                                                    month[9]="Oct";
                                                                    month[10]="Nov";
                                                                    month[11]="Dec";
                                                                    //alert(currentdt.getMonth()+1);
                                                                   var mmm=month[currentdt.getMonth()];
                                                                   var dateString=dt+"/"+mmm+"/"+year;
                                                                   var exDate=new Date(dateString);
                                                                   this.subWebMailExpire.setDataValue(exDate);
                                                          }else{
                                                              var currentdt=new Date();
                                                               var yy=currentdt.getFullYear();
                                                               var dt=currentdt.getDate();
                                                               var month=new Array(12);
                                                                    month[0]="Jan";
                                                                    month[1]="Feb";
                                                                    month[2]="Mar";
                                                                    month[3]="Apr";
                                                                    month[4]="May";
                                                                    month[5]="Jun";
                                                                    month[6]="Jul";
                                                                    month[7]="Aug";
                                                                    month[8]="Sep";
                                                                    month[9]="Oct";
                                                                    month[10]="Nov";
                                                                    month[11]="Dec";
                                                                    
                                                                   var mmm=month[currentdt.getMonth()+1];
                                                                   var dateString=dt+"/"+mmm+"/"+yy;
                                                                   var exDate=new Date(dateString);
                                                                   this.subWebMailExpire.setDataValue(exDate);
                                                          }
                                                    }
                                            }
                                            //read only dialog box
                                            this.Dilog_subscription_WebMail.setUserPrompt(this.subWebmailProduct.getDataValue()+" you wish to purchase");
                                            this.Dilog_subscription_WebMail.show();
                                        }
                                        else{
                                            this.subscriNotEnoughtbal.show();
                                        }
                                }
                                
                                else if(record.price < this.subAccFundBalance.getDataValue()){// enought balance---[product_plans.price] < [accounts.balance] 
                                          var productName=this.subWebmailProduct.getDisplayValue();
                                          this.subscriWebM1.setUserPrompt("Are you sure you want to Buy/Subscribe to the Product "+productName+"<br>This cannot be reversed if you click 'Yes Please'");
                                          this.subscriWebM1.show();
                                  
                                }
                                else{
                                       this.subscriNotEnoughtbal.show();
                                }
                     }
            }
            
		  
	  } catch(e) {
		  console.error('ERROR IN subWebmailBuyClick: ' + e); 
	  } 
  },
  subWebmailProductChange: function(inSender) {
	  try {
            var count=this.ProdcutPlansTB.getCount(); 
            for(var j=0 ; j<count ; j++){
                     var record=this.ProdcutPlansTB.getData()[j];
                     //alert(record.planId);
                    if(record.planId==this.subWebmailProduct.getDataValue()){	
                        var productPrice=record.price;
                        var productCr=record.credits;
                        var prodAmount=record.amount;
                        //alert(prodAmount);
                        this.subWebMailAmount.setDataValue(subWebMailAmount);
                        this.subWebMailPrice.setDataValue(productPrice);
                        this.subWebMailCredit.setDataValue(productCr);
                         var BTrue=true;
                         this.subWebMailRenew.setDataValue(BTrue);
                         this.subWebMailDate.setDataValue(new Date().getTime());
                         if(record.subscription){
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var year=yy+1;
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        //alert(currentdt.getMonth()+1);
                                       var mmm=month[currentdt.getMonth()];
                                       var dateString=dt+"/"+mmm+"/"+year;
                                       var exDate=new Date(dateString);
                                       this.subWebMailExpire.setDataValue(exDate);
                              }else{
                                  var currentdt=new Date();
                                   var yy=currentdt.getFullYear();
                                   var dt=currentdt.getDate();
                                   var month=new Array(12);
                                        month[0]="Jan";
                                        month[1]="Feb";
                                        month[2]="Mar";
                                        month[3]="Apr";
                                        month[4]="May";
                                        month[5]="Jun";
                                        month[6]="Jul";
                                        month[7]="Aug";
                                        month[8]="Sep";
                                        month[9]="Oct";
                                        month[10]="Nov";
                                        month[11]="Dec";
                                        
                                       var mmm=month[currentdt.getMonth()+1];
                                       var dateString=dt+"/"+mmm+"/"+yy;
                                       var exDate=new Date(dateString);
                                       this.subWebMailExpire.setDataValue(exDate);
                              }
                        
                    }
            }
		  
	  } catch(e) {
		  console.error('ERROR IN subWebmailProductChange: ' + e); 
	  } 
  },
  subscriWebM1Button1Click: function(inSender, inButton, inText) {
	  try {
              this.liveFrmWebmail.operation="insert";
              this.liveFrmWebmail.insertData();	
        } catch(e) {
		  console.error('ERROR IN subscriWebM1Button1Click: ' + e); 
	  } 
  },
  
  Dilog_subscription_WebMailButton1Click: function(inSender, inButton, inText) {
      try {
              this.liveFrmWebmail.operation="insert";
              this.liveFrmWebmail.insertData();    
         } catch(e) {
		  console.error('ERROR IN Dilog_subscription_WebMailButton1Click: ' + e); 
	  } 
  },
  liveFrmWebmailSuccess: function(inSender, inData) {
	  try {
             var diff=0;
             //var diff=this.AccountInfoService.getData()[0].balance-this.subWebMailPrice.getDataValue();
             //this.subAccFundBalance.setDataValue(diff);       
             
             var count=this.AccountInfoService.getCount();
             for(var i=0;i<count;i++){
                 diff=this.AccountInfoService.getData()[i].balance-this.subWebMailPrice.getDataValue();
                 this.subAccFundBalance.setDataValue(diff); 
            }
             
             //updat the account table by query
             this.accounts_balance_authSMPT.input.setValue("bal", diff);
             this.accounts_balance_authSMPT.input.setValue("userId", this.subWebMailUserId.getDataValue());	
             this.accounts_balance_authSMPT.update();
             
            //update subscription table for webMail_Activite and webMail_credit
             
             var webMailPlanId=this.subWebmailProduct.getDataValue();
             var count=this.ProdcutPlansTB.getCount(); 
                for(var j=0 ; j<count ; j++){
                    var record=this.ProdcutPlansTB.getData()[j];
                    if(record.planId==webMailPlanId){
                        var productPlanCredit=0;
                        productPlanCredit=record.credits;
                        
                         var countt=this.SubscriptionsTB.getCount();
                          for(var k=0;k<countt;k++){
                             var record_subscription=this.SubscriptionsTB.getData()[k];
                             if(record_subscription.userId==this.subWebMailUserId.getDataValue()){
                                 var webMailCredit=0;
                                 webMailCredit=record_subscription.webmailCredits;
                                 //alert("p_credit="+productPlanCredit);
                                 //alert("s_credit="+webMailCredit);
                                 var total=0;
                                 total=parseInt(webMailCredit)+ parseInt(productPlanCredit);
                                 //alert(total);
                                 this.subscription_webMail.input.setValue("webmailActive",true);
                                 this.subscription_webMail.input.setValue("userId",this.subWebMailUserId.getDataValue());
                                 this.subscription_webMail.input.setValue("webmailCredits",total);
                                 this.subscription_webMail.update();
                             }
                          }
                    }
                }
		    // showing on off panel
            this.panel8.setShowing(true);
            this.webmailHelp.setShowing(false);
            
             //refresh layer
               this.AccountInfoService.update();
               this.SubscriptionsTB.update();
               this.TransactionsTB.update();
               this.ProdcutPlansTB.update();
               this.subscriptionTabGrid.update();
	  } catch(e) {
		  console.error('ERROR IN liveFrmWebmailSuccess: ' + e); 
	  } 
  },
  
  //for WEB MAIL CANCEL----------------------------
    subWebmailCancelClick: function(inSender) {
	  try {
                var count=this.TransactionsTB.getCount();
                for(var i=0 ; i<count ; i++){
                    var record=this.TransactionsTB.getData()[i];
                    
                    if(record.planId==this.subWebmailProduct.getDataValue()){
                        //alert(this.subWebmailProduct.getDataValue());
                        var productName=this.subWebmailProduct.getDisplayValue();
                        this.Dilog_subscription_WebMail_Cancel.setUserPrompt("The subscription for "+productName+" will not be renewed on the expiry date");
                        this.Dilog_subscription_WebMail_Cancel.show();
                    }
                }		  
		  
	  } catch(e) {
		  console.error('ERROR IN subWebmailCancelClick: ' + e); 
	  } 
  },
  Dilog_subscription_WebMail_CancelButton1Click: function(inSender, inButton, inText) {
	  try {
		        this.subscriptions_transaction_Cancel_renew.input.setValue("renew",false);
                this.subscriptions_transaction_Cancel_renew.input.setValue("userId",this.subWebMailUserId.getDataValue());
                this.subscriptions_transaction_Cancel_renew.input.setValue("planId",this.subWebmailProduct.getDataValue());
                
                this.subWebmailCancel.setShowing(false);
		  
	  } catch(e) {
		  console.error('ERROR IN Dilog_subscription_WebMail_CancelButton1Click: ' + e); 
	  } 
  },
  
 
  
  
  
  //for account Funding
  
  subAccFundBuyClick: function(inSender) {
	  try {
                if(this.subAccFundTopup.getDataValue() != null){
                    var topUpDtVal=this.subAccFundTopup.getDataValue();
                    this.cart.setSource("https://www.brapion.com/office/order.php?a=add&pid=33&opt="+topUpDtVal);
                    //this.cart.setSource("https://www.yahoo.com");
                    //this.cart.setSource("http://dev.wavemaker.com");
                    this.layerPay.setShowing(true);
                    this.cart.setShowing(true);
                    //this.layerPay.resetData();
                    this.navSubscription_Pay.update();
                }
                
        		  
		  
	  } catch(e) {
		  console.error('ERROR IN subAccFundBuyClick: ' + e); 
	  } 
  },
  bmProfilesCreateLiveFormSuccess: function(inSender, inData) {
	  try {
		  this.GrpPerLiveFormSuccess(inSender, inData);
		  
	  } catch(e) {
		  console.error('ERROR IN bmProfilesCreateLiveFormSuccess: ' + e); 
	  } 
  },
  bmProfilesCreateChange: function(inSender) {
	  try {
		  this.GrpnameChange(inSender);
		  
	  } catch(e) {
		  console.error('ERROR IN bmProfilesCreateChange: ' + e); 
	  } 
  },
  bmProfilesCreateNewClick: function(inSender) {
	  try {
		  this.setGrpCreateGrpNew4Click(inSender);
		  
	  } catch(e) {
		  console.error('ERROR IN bmProfilesCreateNewClick: ' + e); 
	  } 
  },
  bmProfilesExistingBlur: function(inSender) {
	  try {
		  this.Existing_Groups2Blur(inSender);
		  
	  } catch(e) {
		  console.error('ERROR IN bmProfilesExistingBlur: ' + e); 
	  } 
  },
  bmProfilesExistingChange: function(inSender) {
	  try {
		  this.Existing_Groups2Change(inSender);
		  
	  } catch(e) {
		  console.error('ERROR IN bmProfilesExistingChange: ' + e); 
	  } 
  },
  bmProfilesExistProSaveClick: function(inSender) {
	  try {
		  this.setGrpExistGrpSave4Click(inSender);
		  
	  } catch(e) {
		  console.error('ERROR IN bmProfilesExistProSaveClick: ' + e); 
	  } 
  },
  bmProfilesExistProDeleteClick: function(inSender) {
	  try {
		  this.setGrpExistGrpDelete4Click(inSender);
		  
	  } catch(e) {
		  console.error('ERROR IN bmProfilesExistProDeleteClick: ' + e); 
	  } 
  },
  bmProfilesCreateNew1Click: function(inSender) {
	  try {
		  this.bmProfilesCreateNewClick(inSender);
		  
	  } catch(e) {
		  console.error('ERROR IN bmProfilesCreateNew1Click: ' + e); 
	  } 
  },
  //authSMTP=====================================================
  layerAuthsmtpShow: function(inSender) {
      try {
            this.myUserID.update();
            this.myUserIdQuery.update();
            this.AuthsmtpdomainsTB.update();
            this.liveMaiBoxesAliaseslDojoGrid.update();
            
            var myUserIdQueryValue=this.myUserIdQuery.getData()[0];
            //alert(myUserIdQueryValue.c0);
            //alert(this.AuthsmtpdomainsTB.getCount());
            var count=this.AuthsmtpdomainsTB.getCount();
            for(var i=0;i<count;i++){
                var record=this.AuthsmtpdomainsTB.getData()[i];
                //alert(record.userId+"---"+myUserIdQueryValue.c0);
                if(record.userId==myUserIdQueryValue.c0){
                    //alert("i="+i);
                    
                    //for the panel 40 & 42 point 1a) b)---comp Domain
                    if(record.companyDomain == ""){
                        this.panel40.setShowing(true);
                        this.panel42.setShowing(false);
                    }else{
                        this.panel40.setShowing(false);
                        this.panel42.setShowing(true);
                        this.existDomSet.setDataValue(record.companyDomain);
                    }
                    //alert("hi");
                    //alert(record.authenticatedDomain);
                     //for the panel 41 & 43 point 2a) b)-- auth domain
                    
                    if(record.authenticatedDomain == ""){
                        this.panel41.setShowing(true);
                        this.panel43.setShowing(false);
                    }else{
                        this.panel41.setShowing(false);
                        this.panel43.setShowing(true);
                        this.newDomSet.setDataValue(record.authenticatedDomain);
                        this.regMailDomain.setValue("caption",record.authenticatedDomain);
                    }
                    
                }
                
            }
            //set the panel title here
            var registerMailContainerTitle="Register up to "+this.subAuthsmtpProduct.getDisplayValue();
            this.registerMailContainer.setValue("title",registerMailContainerTitle);
            	  
	  } catch(e) {
		  console.error('ERROR IN layerAuthsmtpShow: ' + e); 
	  } 
  },
  //----for the existingDomain
  existDomNewClick: function(inSender) {
	  try {
          //for the validation of existDomEntry
		  if(this.existDomEntry.getDataValue() != null && this.existDomSuffix.getDataValue() != null){
              var value=this.existDomEntry.getDataValue();
              var newExistDomVal=new Array();
              var existDomVal=new Array();
              existDomVal=value.split(".");
              var i=0;
              for(var k=0;k<existDomVal.length;k++){
                //alert("value["+k+"]-"+existDomVal[k]);
                if(existDomVal[k].replace(/^\s+|\s+$/g,"") != "co" && existDomVal[k].replace(/^\s+|\s+$/g,"") != "com" && existDomVal[k].replace(/^\s+|\s+$/g,"") != "CO" && existDomVal[k].replace(/^\s+|\s+$/g,"") != "COM" && existDomVal[k].replace(/^\s+|\s+$/g,"") != "https" && existDomVal[k].replace(/^\s+|\s+$/g,"") != "http"  ){
                     if(existDomVal[k].split("://")[1] != null){
                          //alert("chk condition for ://");
                           var temp=existDomVal[k].split("://")[1];
                           var t=temp.replace(/^\s+|\s+$/g,"");
                           if(t!="www" && t!="WWW" && t!="http" && t!="https" && t!="co" && t!="CO" && t!="com" && t!="COM")
                           {
                               if(existDomVal[k].match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ){
                                 app.alert("special character is not valid");
                               }
                               else{
                                   //alert("://--- Length="+t.length);
                                   if(t.length>4){
                                         newExistDomVal[i]=t;
                                         i++;
                                   }
                               }
                             
                           }
                     }
                     else{
                            //alert("chk condition other than ://");
                            if(existDomVal[k].match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ){
                               app.alert("special character is not valid");
                            }
                            else{
                                if(existDomVal[k].replace(/^\s+|\s+$/g,"")!="www" && existDomVal[k].replace(/^\s+|\s+$/g,"")!="WWW" && existDomVal[k].replace(/^\s+|\s+$/g,"")!="http" && existDomVal[k].replace(/^\s+|\s+$/g,"")!="https" &&  existDomVal[k].replace(/^\s+|\s+$/g,"")!="co" && existDomVal[k].replace(/^\s+|\s+$/g,"")!="CO" && existDomVal[k].replace(/^\s+|\s+$/g,"")!="com" && existDomVal[k].replace(/^\s+|\s+$/g,"")!="COM"){
                                    var otherVal=existDomVal[k].replace(/^\s+|\s+$/g,"");
                                    //alert("other than :// length="+existDomVal[k].replace(/^\s+|\s+$/g,"").length);
                                    if(existDomVal[k].replace(/^\s+|\s+$/g,"").length>4){
                                        newExistDomVal[i]=existDomVal[k];
                                        i++;
                                    }
                                }
                            }
                            
                      }
                      
                  }
                  
              }
              
              var final = "";
              for(var k=0;k<newExistDomVal.length;k++){
                  final = final+newExistDomVal[k];
                 // alert(k+final);
              }
              
              //for the domain suffix
              var domainSuff=this.existDomSuffix.getDisplayValue();
              var domSuffExistWMVlength=this.domainSuffixExistingWMV.getCount();
              //alert("pulldown dom suffix DisplayValue="+domainSuff);
              //alert("domSuffExistWMVlength ="+domSuffExistWMVlength);
              for(var i=0;i<domSuffExistWMVlength;i++){
                  var record=this.domainSuffixExistingWMV.getData()[i];
                  //alert("domainSuffixExistingWMV dataValue["+i+"]="+record.dataValue);
                  if(record.dataValue==domainSuff){
                      if(final!=""){
                        var CompanyDomain=final+domainSuff;
                        this.ExisitCoDom_Iptype.setDataValue(true);
                        this.ExisitCoDom_IpInstances.setDataValue(true);
                        this.ExisitCoDom_CompanyDomain.setDataValue(CompanyDomain);
                        this.ExisitCoDom_postfix.setDataValue("ignore");
                        this.DialogAuthSmtpExisitCoDomain.setUserPrompt("Please double check "+CompanyDomain+" is correctly typed.<br>This CANNOT be changed if you click 'Proceed'");
                        this.DialogAuthSmtpExisitCoDomain.show();
                        break;
                      }
                      
                  }
              }
              
         }else{
              app.alert("Domain name and Domain suffix are required");
		  }
		  
	  } catch(e) {
		  console.error('ERROR IN existDomNewClick: ' + e); 
	  } 
  },
  DialogAuthSmtpExisitCoDomainButton2Click: function(inSender, inButton, inText) {
      try {
		  this.addAuthSMTP_ExistCoComp.insertData();
         
		  
	  } catch(e) {
		  console.error('ERROR IN DialogAuthSmtpExisitCoDomainButton2Click: ' + e); 
	  } 
  },
  
  addAuthSMTP_ExistCoCompSuccess: function(inSender, inData) {
      try {
		  this.existDomSet.setDataValue(this.existDomEntry.getDisplayValue()+this.existDomSuffix.getDisplayValue());
           //for clean the existDomEntry
         this.existDomEntry.clear();
         this.existDomSuffix.clear();
         
         //showing panel
         this.panel40.setShowing(false);
         this.panel42.setShowing(true);
		  
	  } catch(e) {
		  console.error('ERROR IN addAuthSMTP_ExistCoCompSuccess: ' + e); 
	  } 
  },
  //---------for the NewDomain
  newDomNewClick: function(inSender) {
      try {
		  if(this.existDomSet.getDataValue() == null){//if your exisiting comp domain = null
              this.DialogAuthSmtpNewAuthDomain.show();
		  }else{
                if(this.newDomEntry.getDataValue() != null && this.newDomSuffix.getDataValue() != null){
                    var value=this.newDomEntry.getDataValue();
                    var newDomVal=new Array();
                    var currentDomVal=new Array();
                    currentDomVal=value.split(".");
                    var i=0;
                    for(var k=0;k<currentDomVal.length;k++){
                        //alert("value["+k+"]-"+currentDomVal[k]);
                        if(currentDomVal[k].replace(/^\s+|\s+$/g,"") != "co" && currentDomVal[k].replace(/^\s+|\s+$/g,"") != "com" && currentDomVal[k].replace(/^\s+|\s+$/g,"") != "CO" && currentDomVal[k].replace(/^\s+|\s+$/g,"") != "COM" && currentDomVal[k].replace(/^\s+|\s+$/g,"") != "https" && currentDomVal[k].replace(/^\s+|\s+$/g,"") != "http"  ){
                            if(currentDomVal[k].split("://")[1] !=null ){
                               // alert("chk condition for ://");
                                var temp=currentDomVal[k].split("://")[1];
                                var t=temp.replace(/^\s+|\s+$/g,"");
                                if(t!="www" && t!="WWW" && t!="http" && t!="https" && t!="co" && t!="CO" && t!="com" && t!="COM")
                                {
                                    if(currentDomVal[k].match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ){
                                         app.alert("special character is not valid");
                                    }
                                    else{
                                           //alert("://--- Length="+t.length);
                                           if(t.length>4){
                                                 newDomVal[i]=t;
                                                 i++;
                                           }
                                    }
                                }
                                
                                
                            }
                            else{
                                   // alert("chk condition other than ://")
                                    if(currentDomVal[k].match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ){
                                       app.alert("special character is not valid");
                                    }
                                    else{
                                        if(currentDomVal[k].replace(/^\s+|\s+$/g,"")!="www" && currentDomVal[k].replace(/^\s+|\s+$/g,"")!="WWW" && currentDomVal[k].replace(/^\s+|\s+$/g,"")!="http" && currentDomVal[k].replace(/^\s+|\s+$/g,"")!="https" &&  currentDomVal[k].replace(/^\s+|\s+$/g,"")!="co" && currentDomVal[k].replace(/^\s+|\s+$/g,"")!="CO" && currentDomVal[k].replace(/^\s+|\s+$/g,"")!="com" && currentDomVal[k].replace(/^\s+|\s+$/g,"")!="COM"){
                                            var otherVal=currentDomVal[k].replace(/^\s+|\s+$/g,"");
                                            
                                          //  alert("other than :// length="+currentDomVal[k].replace(/^\s+|\s+$/g,"").length);
                                            if(currentDomVal[k].replace(/^\s+|\s+$/g,"").length>4){
                                                newDomVal[i]=currentDomVal[k];
                                                i++;
                                            }
                                        }
                                    }
                           }
                        }
                    }
                      var final = "";
                      for(var k=0;k<newDomVal.length;k++){
                          final = final+newDomVal[k];
                         // alert(k+" "+final);
                      }
                      
                  //for the domain suffix
                  var newdomainSuff=this.newDomSuffix.getDisplayValue();
                  var domainSuffixNewWMVlength=this.domainSuffixNewWMV.getCount();
                  //alert("pulldown dom suffix DisplayValue="+domainSuff);
                  //alert("domSuffExistWMVlength ="+domSuffExistWMVlength);
                  for(var i=0;i<domainSuffixNewWMVlength;i++){
                      var record=this.domainSuffixNewWMV.getData()[i];
                      //alert("domainSuffixExistingWMV dataValue["+i+"]="+record.dataValue);
                      if(record.dataValue==newdomainSuff){
                          if(final!=""){
                            var NewCompanyDomain=final+newdomainSuff;
                            //alert("NewCompanyDomain"+NewCompanyDomain);
                            
                            this.DialogAuthSmtpNewAuthDomain_insert.setUserPrompt("Please double check "+NewCompanyDomain+" is correctly typed.<br>This CANNOT be changed if you click 'Proceed'");
                            this.DialogAuthSmtpNewAuthDomain_insert.show();
                            break;
                          }
                          
                      }
                  }
                }
                else{
                    app.alert("Domain name and Domain suffix are required");
                }
              
		 }
		  
	  } catch(e) {
		  console.error('ERROR IN newDomNewClick: ' + e); 
	  } 
  },
  DialogAuthSmtpNewAuthDomain_insertButton2Click: function(inSender, inButton, inText) {
      try {
          this.newDomauthenticated_domain.setDataValue(this.newDomEntry.getDisplayValue()+this.newDomSuffix.getDisplayValue());
          this.authSmtp__NewDomain_update_authenticated_domain_postfix.input.setValue("companyDomain",this.existDomSet.getDataValue());
          this.authSmtp__NewDomain_update_authenticated_domain_postfix.input.setValue("authenticatedDomain",this.newDomauthenticated_domain.getDataValue());
          this.authSmtp__NewDomain_update_authenticated_domain_postfix.input.setValue("userId",this.newDomUserId.getDataValue());
          
          this.newDomSet.setDataValue(this.newDomEntry.getDisplayValue()+this.newDomSuffix.getDisplayValue());
          this.newDomEntry.clear();
          this.newDomSuffix.clear();
         
          //showing panel
          this.panel41.setShowing(false);
          this.panel43.setShowing(true);
	    } catch(e) {
		  console.error('ERROR IN DialogAuthSmtpNewAuthDomain_insertButton2Click: ' + e); 
	  } 
  },
  
  //--------------------------Dojo Grid
  liveMailDojoGridC0Format: function( inValue, rowId, cellId, cellField, cellObj, rowObj) {
      try {
                //alert("rowId"+rowId);
                //alert(this.liveMaiBoxesAliaseslDojoGrid.getCount());
                var count=this.liveMaiBoxesAliaseslDojoGrid.getCount();
                for(var i=0;i<count;i++){
                    if(i==rowId){
                        var record=this.liveMaiBoxesAliaseslDojoGrid.getData()[i];
                        //alert(record.c0+"@"+record.c1);
                        return record.c0+"@"+record.c1;
                    }
                }
		  
	  } catch(e) {
		  console.error('ERROR IN liveMailDojoGridC0Format: ' + e); 
	  } 
  },
  
  liveMailDojoGridC2Format: function( inValue, rowId, cellId, cellField, cellObj, rowObj) {
	  try {
                //alert("rowId["+rowId+"]="+inValue);    	  
                if(inValue==1){
                    return "Mailbox";
                }else{
                    return "Alias";
                }
		  
	  } catch(e) {
		  console.error('ERROR IN liveMailDojoGridC2Format: ' + e); 
	  } 
  },
  liveMailDojoGridCustomField4Format: function( inValue, rowId, cellId, cellField, cellObj, rowObj) {
	  try {
                return "reset";
		  
	  } catch(e) {
		  console.error('ERROR IN liveMailDojoGridCustomField4Format: ' + e); 
	  } 
  },
  
  regMailNewClick: function(inSender) {
      try {
          this.myUserID.update();
          this.myUserIdQuery.update();
          var myUserIdQueryValue=this.myUserIdQuery.getData()[0];
         // alert("record.userId==myUserIdQueryValue"+myUserIdQueryValue.c0);
		  //alert("count="+this.TransactionsTB.getCount());
          var count=this.TransactionsTB.getCount();
          for(var i=0;i<count;i++){
              var record=this.TransactionsTB.getData()[i];
              //alert(i+"==="+record.planId);
              
              if(record.expires>new Date().getTime() && record.userId==myUserIdQueryValue.c0){
                 // alert(i+"==PlanId==="+record.planId);
                  
                  //alert("BEFORE   mailbox="+mailbox+"aliases="+aliases);
                  if(record.planId==1){
                      mailbox=mailbox+1;
                      aliases=aliases+2;
                      //alert("mailbox="+mailbox+"aliases="+aliases);
                  }else if(record.planId==2){
                      mailbox=mailbox+2;
                      aliases=aliases+3;
                      //alert("mailbox="+mailbox+"aliases="+aliases);
                  }else if(record.planId==3){
                      mailbox=mailbox+3;
                      aliases=aliases+5;
                      //alert("mailbox="+mailbox+"aliases="+aliases);
                  }else if(record.planId==4){
                      mailbox=mailbox+5;
                      aliases=aliases+5;
                      //alert("mailbox="+mailbox+"aliases="+aliases);
                  }else if(record.planId==5){
                      mailbox=mailbox+10;
                      aliases=aliases+10;
                      //alert("mailbox="+mailbox+"aliases="+aliases);
                  }
                 // alert("AFTER   mailbox="+mailbox+"aliases="+aliases);
              }
              
          }
          
          
          var countAuthsmtpMail=this.AuthsmtpmailTB.getCount();
          for(var i=0;i<countAuthsmtpMail;i++){
              var record=this.AuthsmtpmailTB.getData()[i];
              if(record.userId==myUserIdQueryValue.c0){
                  var email_type=record.emailType;
                  var postfix=record.postfix;
                  var email_address=record.emailAddress;
                  //alert("email_type="+email_type+"  postfix="+postfix+"  email_address="+email_address);
                  if(email_type==1 && postfix== "live" && email_address!="abuse" && email_address!="postmaster" && email_address!="webmaster" && email_address!="hostmaster" && email_address!="maximails" && email_address!="error"){
                      //alert(record.id+"email_type==1");
                      mailBox_authsmtpMail=mailBox_authsmtpMail+1;
                  }
                  else if(email_type==2 && postfix== "live" && email_address!="abuse" && email_address!="postmaster" && email_address!="webmaster" && email_address!="hostmaster" && email_address!="maximails" && email_address!="error"){
                      //alert(record.id+"email_type==2");
                      aliases_authsmtpMail=mailBox_authsmtpMail+1;
                  }
              }
          }
          
          if(mailBox_authsmtpMail >= mailbox){
              this.DialogAuthSmtp_registerUpTo_mailBox.show();
          }
          if(aliases_authsmtpMail >= aliases){
              this.DialogAuthSmtp_registerUpTo_aliases.show();
          }
          
           var final = "";
          //for the regMailUser validation
          var value=this.regMailUser.getDataValue();
          if(value != null){
              var newVal=new Array();
              var currentVal=new Array();
              currentVal=value.split(".");
              var i=0;
              for(var k=0;k<currentVal.length;k++){
                         if(currentVal[k].replace(/^\s+|\s+$/g,"") != "co" && currentVal[k].replace(/^\s+|\s+$/g,"") != "com" && currentVal[k].replace(/^\s+|\s+$/g,"") != "CO" && currentVal[k].replace(/^\s+|\s+$/g,"") != "COM" && currentVal[k].replace(/^\s+|\s+$/g,"") != "https" && currentVal[k].replace(/^\s+|\s+$/g,"") != "http"  && currentVal[k].replace(/^\s+|\s+$/g,"")!="net" && currentVal[k].replace(/^\s+|\s+$/g,"")!="org" && currentVal[k].replace(/^\s+|\s+$/g,"")!="ltd" && currentVal[k].replace(/^\s+|\s+$/g,"")!="info"){
                            if(currentVal[k].split("://")[1] !=null ){
                               // alert("chk condition for ://");
                                var temp=currentVal[k].split("://")[1];
                                var t=temp.replace(/^\s+|\s+$/g,"");
                                if(t!="www" && t!="WWW" && t!="http" && t!="https" && t!="co" && t!="CO" && t!="com" && t!="COM")
                                {
                                    if(currentVal[k].match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ){
                                         app.alert("special character is not valid");
                                    }
                                    else{
                                          // alert("://--- Length="+t.length);
                                           if(t.length>2){
                                                 newVal[i]=t;
                                                 i++;
                                           }
                                    }
                                }
                                
                                
                            }
                            else{
                                    
                                   // alert("chk condition other than ://")
                                    if(currentVal[k].match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ){
                                       app.alert("special character is not valid");
                                    }
                                    else{
                                        if(currentVal[k].replace(/^\s+|\s+$/g,"")!="www" && currentVal[k].replace(/^\s+|\s+$/g,"")!="WWW" && currentVal[k].replace(/^\s+|\s+$/g,"")!="http" && currentVal[k].replace(/^\s+|\s+$/g,"")!="https" &&  currentVal[k].replace(/^\s+|\s+$/g,"")!="co" && currentVal[k].replace(/^\s+|\s+$/g,"")!="CO" && currentVal[k].replace(/^\s+|\s+$/g,"")!="com" && currentVal[k].replace(/^\s+|\s+$/g,"")!="COM" && currentVal[k].replace(/^\s+|\s+$/g,"")!="net" && currentVal[k].replace(/^\s+|\s+$/g,"")!="org" && currentVal[k].replace(/^\s+|\s+$/g,"")!="ltd" && currentVal[k].replace(/^\s+|\s+$/g,"")!="info"){
                                            var otherVal=currentVal[k].replace(/^\s+|\s+$/g,"");
                                            
                                           // alert("other than :// length="+currentVal[k].replace(/^\s+|\s+$/g,"").length);
                                            if(currentVal[k].replace(/^\s+|\s+$/g,"").length>2){
                                                
                                                if(k!=0 && (currentVal[k-1].replace(/^\s+|\s+$/g,"")=="com" || currentVal[k-1].replace(/^\s+|\s+$/g,"")=="co")){
                                                       // alert("hi");
                                                        break;
                                                }
                                                else{
                                                    newVal[i]=currentVal[k];
                                                    i++;
                                                }
                                            }
                                        }
                                    }
                           }
                        }
             }
             for(var k=0;k<newVal.length;k++){
               final = final+newVal[k];
               alert(k+" "+final);
            }
          }
          
         
          
            
         //validation for the forwarded to
         if(this.regMailForward.getDataValue()!==null){
             var forwardedToValue=this.regMailForward.getDataValue();
             //alert(forwardedToValue);
             var newForwardedValue=forwardedToValue.split(".");
             for(var i=0;i<newForwardedValue.length;i++){
                 var val1=newForwardedValue[i].match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/);
                 alert(val1);
                 if(val1=="@"){
                     var val2=newForwardedValue[i].split("@");
                     alert("length="+val2[0].length+"----"+val2[1].length);
                     alert("value="+val2[0]+"----"+val2[1]+"---"+newForwardedValue[1]);
                     if(val2[0].length>2 && val2[1].length >4 && newForwardedValue[1] == ""){
                        //alert("hiii");    
                     }else{
                         app.alert("Email address is not valid");
                     }
                }else{
                     app.alert("Email address is not valid");
                 }
                 break;
             }
             
         }
             
		  mailbox=0;
          aliases=0;
          mailBox_authsmtpMail=0;
          aliases_authsmtpMail=0;
	  } catch(e) {
		  console.error('ERROR IN regMailNewClick: ' + e); 
	  } 
  },
 //end authSmtp=================
  
 
  
  button1Click: function(inSender) {
	  try {
                alert("Button one clicked");		  
		  
	  } catch(e) {
		  console.error('ERROR IN button1Click: ' + e); 
	  } 
  },
  button2Click: function(inSender) {
	  try {
   		  
		  alert("Button Two clicked");
	  } catch(e) {
		  console.error('ERROR IN button2Click: ' + e); 
	  } 
  },
  _end: 0
    });
    
    
